39. jQuery-通過對映方式繫結事件
阿新 • • 發佈:2018-12-31
1. 效果圖
2.html程式碼
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>39 jQuery-通過對映方式繫結事件</title> <style type="text/css"> body{font-size:13px} .clsTip{border:#ccc 1px solid; background-color:#eee;margin-top:15px; padding:5px;width:205px;display:none} .txt{border:#666 1px solid;padding:3px} </style> </head> <body> <div>姓名:<input type="text" class="txt" /></div> <div id="divTip" class="clsTip"></div> <script src="../jquery.min.js"></script> <script type="text/javascript"> //第二種方法 $(function(){ $(".txt").bind({ focus: function() { $("#divTip").show().html("執行的是focus事件"); }, change: function() { $("#divTip").show().html("執行的是change事件"); } }); }); </script> </body> </html>