JS笔记
javascript绑定事件
JavaScript Code复制内容到剪贴板
- window.onload = function() {
- draw();
- var saveButton = document.getElementById("saveImageBtn");
- bindButtonEvent(saveButton, "click", saveImageInfo);
- var dlButton = document.getElementById("downloadImageBtn");
- bindButtonEvent(dlButton, "click", saveAsLocalImage);
- };
- function bindButtonEvent(element, type, handler)
- {
- if(element.addEventListener) {
- element.addEventListener(type, handler, false);
- } else {
- element.attachEvent('on'+type, handler);
- }
- }
- function saveImageInfo ()
- {
- var mycanvas = document.getElementById("thecanvas");
- var image = mycanvas.toDataURL("image/png");
- var w=window.open('about:blank','image from canvas');
- w.document.write("<img src='"+image+"' alt='from canvas'/>");
- }
绑定未来元素
JavaScript Code复制内容到剪贴板
- $(document).on('click','#dianji1',function(){
- alert('11');
- });
支持的事件有:
参照:https://www.w3school.com.cn/jquery/jquery_ref_events.asp
| blur | 事件会在对象失去焦点时发生 | <input type="text" id="fname" onblur="upperCase()" /> |
| focus | 当元素获得焦点时,发生 focus 事件 | <input type="text" onfocus="myFunction()"> |
| focusin | ||
| focusout | ||
| load | ||
| resize | ||
| scroll | ||
| unload | ||
| click | ||
| dblclick | ||
| mousedown | ||
| mouseup | ||
| mousemove | ||
| mouseover | ||
| mouseout | ||
| mouseenter | ||
| mouseleave | ||
| change | ||
| select | ||
| submit | ||
| keydown | ||
| keypress | ||
| keyup | ||
| error | ||
| contextmenu |
