JS笔记
前端笔记 2016-10-14 13:28:05 前端笔记   笔记   

 

 

javascript绑定事件

JavaScript Code复制内容到剪贴板
  1. window.onload = function() {      
  2.             draw();      
  3.             var saveButton = document.getElementById("saveImageBtn");      
  4.             bindButtonEvent(saveButton, "click", saveImageInfo);      
  5.             var dlButton = document.getElementById("downloadImageBtn");      
  6.             bindButtonEvent(dlButton, "click", saveAsLocalImage);      
  7.         };    
  8.     
  9. function bindButtonEvent(element, type, handler)      
  10.             {      
  11.                    if(element.addEventListener) {      
  12.                       element.addEventListener(type, handler, false);      
  13.                    } else {      
  14.                       element.attachEvent('on'+type, handler);      
  15.                    }      
  16.             }    
  17.   
  18. function saveImageInfo ()     
  19.             {    
  20.                 var mycanvas = document.getElementById("thecanvas");    
  21.                 var image    = mycanvas.toDataURL("image/png");    
  22.                 var w=window.open('about:blank','image from canvas');    
  23.                 w.document.write("<img src='"+image+"' alt='from canvas'/>");    
  24.             }    

 

绑定未来元素

JavaScript Code复制内容到剪贴板
  1. $(document).on('click','#dianji1',function(){  
  2.     alert('11');  
  3. });  

支持的事件有:

blur
focus
focusin
focusout
load
resize
scroll
unload
click
dblclick
mousedown
mouseup
mousemove
mouseover
mouseout
mouseenter
mouseleave
change
select
submit
keydown
keypress
keyup
error
contextmenu

 

 

 

 

 

本文来自于:http://www.yoyo88.cn/note/frontend/42.html

Powered by yoyo苏ICP备15045725号-1