jQuery中 bind的用法簡單介紹,jquerybind

來源:互聯網
上載者:User

jQuery中 bind的用法簡單介紹,jquerybind

bind介紹

bind() 方法為被選元素添加一個或多個事件處理常式,並規定事件發生時啟動並執行函數。

文法

$(selector).bind(event,data,function)

event 必須。添加到元素的一個或多個事件如:click,mouseover,mouseup,change,select

data 可不填。傳遞到函數的額外資料,如:$(selector).bind(“click”,”input”,function(){});

function(){} 必填。綁定事件觸發的函數

bind綁定多個函數

$("button").bind({ // 注意它的格式是 json  click:function(){$("div").css("border","5px solid orange");},  mouseover:function(){$("div").css("background-color","red");},   mouseout:function(){$("div").css("background-color","#FFFFFF");}  });

4.bind綁定資料

// bind() 綁定 click 事件傳 參數2 並且列印出 參數2 $('button').bind('click',['路飛','索隆','烏索普'],function(event){  alert(event.data[0]); // 路飛 });

5.unbind bind事件移除

    html 代碼 

<button>unbind()</button> <p>點我刪除上邊按鈕的事件</p>

    js 代碼 

 // bind() 綁定多個點擊事件 $('button').click(function(){  alert('我是第一個點擊事件'); }); $('button').click(function(){  alert('我是第二個點擊事件'); }); $('button').bind('click',function(){  alert('我是第三個點擊事件'); }); // unbind() 刪除點擊事件 $('p').bind('click',function(){  $('button').unbind('click');  alert('button 的點擊事件被刪除'); });

以上所述是小編給大家介紹的jQuery中的 bind用法簡單介紹,希望對大家有所協助,如果大家有任何疑問請給我留言,小編會及時回複大家的。在此也非常感謝大家對幫客之家網站的支援!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.