实例:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <button>点击</button> </body> <script src="../js/jquery-1.10.1.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> $(function(){ // $('button').click(function(){ // alert('今天天气不错') // }) // bind() // $('button').bind('click',function(){ // alert('今天天气好晴朗') // }) // $('button').bind('click mousemove',function(){ // alert('处处好风光') // }) // $('button').bind({ // 'click':function(){ // alert('今天天气好晴朗') // }, // 'mouseover':function(){ // alert('处处好风光') // } // }) // $('button').click(function(){ // alert('今天天气不错1') // }) // $('button').mousemove(function(){ // alert('今天天气不错2') // }) // $('button').bind('click',a) // $('button').bind('mouseover',b) // function a(){ // alert('哈哈哈哈') // } // function b(){ // alert('呵呵呵呵') // } }) </script> </html>实例:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <button>点击</button> </body> <script src="../js/jquery-1.10.1.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> $(function(){ // $('button').bind('click',a) // $('button').bind('mouseover',b) // function a(){ // alert('哈哈哈哈') // } // function b(){ // alert('呵呵呵呵') // } // $('button').unbind('click') $('button').bind({ 'click':function(){ alert(111111111) }, 'mouseover':function(){ alert(2222222222) } }) $('button').unbind('mouseover') }) </script> </html>鼠标事件 click() 点击事件 dblclick() 双击 mousedown() 鼠标按下 mouseup() 鼠标弹起 mouseover() 鼠标移动 **他们俩个的区别在于:over和out事件碰到子元素也会触发事件,enter和leave不会
mouseout() 鼠标移出 mouseenter() 鼠标移入 mouseleave() 鼠标移出 mousemove() 鼠标移入移出 滚动事件 scroll() 滚动 表单事件 focus() 获取焦点 blur() 失去焦点 focusin() 获取焦点 focusout() 失去焦点 submit() 提交 select() 选中文本 change() 改变文本 浏览器事件 resize() 缩放浏览器 键盘事件 keydown() 键盘按下 keyup() 键盘弹起 keypress() 键盘简码
5:如果大家想要用废弃的方法在新版本里面,可以下载 jquery-migrate.js 文件,来向下兼容已被删除掉的方法
实例: 阻止事件冒泡
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> div{ width: 300px; height: 300px; background: red; } p{ width: 150px; height: 150px; background: blue; } span{ float: left; width: 50px; height: 50px; background: pink; } </style> </head> <body> <div> <p> <span> </span> </p> </div> </body> <script src="../js/jquery-1.10.1.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> $('div').click(function(e){ alert('我是div') e.stopPropagation() }) $('p').click(function(e){ alert('我是p') e.stopPropagation() }) $('span').click(function(e){ alert('我是span') e.stopPropagation() }) </script> </html>实例: 阻止默认行为
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <a href="10事件命名空间.html">跳转</a> </body> <script src="../js/jquery-1.10.1.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> $('a').click(function(e){ // e.preventDefault(); return false; }) </script> </html>实例:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> p{ position: fixed; } </style> </head> <body style="height: 3000px;"> <p></p> </body> <script src="../js/jquery-1.10.1.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> $(document).mousemove(function(e){ // alert(e.type) // $('p').html(e.clientX+','+e.clientX) // $('p').html(e.pageX+','+e.pageY) $('p').html(e.screenX+','+e.screenY) }) </script> </html>