38. jQuery-使用bind()方法繫結事件
阿新 • • 發佈:2018-12-31
語法格式:
bind(type, [data], fn)
其中引數type為一個或多個型別的字串,如“click”或“change”,也可以自定義型別;可以被引數type呼叫的型別包括blur、focus、load、resize、scroll、unload、click、 dblclick、mousedown、mouseup、mousemove、mouseover、mouseout、mouseenter、mouseleave、change、select、submit、keydown、keypress、keyup、error。
引數data是作為event.data屬性值傳遞給事件物件的額外資料物件。
引數fn是繫結到每個選擇元素的事件中的處理函式。
1. 效果圖
2.html程式碼
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>38 jQuery-使用bind()方法繫結事件</title> <style type="text/css"> .btn {border:#666 1px solid;padding:2px;width:50px; filter: progid:DXImageTransform.Microsoft .Gradient(GradientType=0,StartColorStr=#ffffff, EndColorStr=#ECE9D8);} </style> </head> <body> <input id="btnBind" type="button" value="Button" class="btn"> <script src="../jquery.min.js"></script> <script type="text/javascript"> //第二種方法 $(function(){ $("#btnBind").bind("click mouseout", function(){ //點選後按鈕不可用 $(this).attr("disabled", "disabled") }) }); </script> </body> </html>