经过上一个函数传过来的值判断,若是成功就怎么样,若是失败就怎么样。javascript
21 $('#btn1').click(function(){ 22 // return 100 23 return true 24 }) 25 $('#btn1').click(function(e){ 26 // alert(e.result) 27 if (e.result) { 28 alert('进入下一关!') 29 }else{ 30 alert('Game Over!') 31 } 32 })
若是为DOM元素的同一事件类型绑定了多个事件处理函数,你能够使用result属性获取上一个事件处理函数执行的返回值。css
1 <!DOCTYPE html> 2 <html lang="en"> 3 <style> 4 </style> 5 <head> 6 <meta charset="UTF-8"> 7 <title>演示文档</title> 8 <script type="text/javascript" src="jquery-3.1.1.min.js"></script> 9 <style type="text/css"> 10 input{width: 100px;height: 30px;} 11 div{width: 100px;height: 100px;border:1px solid green;} 12 </style> 13 </style> 14 </head> 15 <body> 16 <h3>jQuery事件对象</h3> 17 <div id="div1"><p id="pid"></p></div> 18 <input id="btn1" type="button" value="事件对象"> 19 <script type="text/javascript"> 20 $(function(){ 21 $('#btn1').click(function(){ 22 // return 100 23 return true 24 }) 25 $('#btn1').click(function(e){ 26 // alert(e.result) 27 if (e.result) { 28 alert('进入下一关!') 29 }else{ 30 alert('Game Over!') 31 } 32 }) 33 }) 34 </script> 35 </body> 36 </html>