Jquery中的事件綁定$("#btn").bind("click",function(){ }),

來源:互聯網
上載者:User

Jquery中的事件綁定$("#btn").bind("click",function(){ }),

Jquery中的事件綁定:$("#btn").bind("click",function(){  })

因為每次都這麼調用太麻煩,所以jquery就用$("#btn").click(function(){})來進行簡化


jQuery中事件綁定的問題

event 需要去觸發,是調用js的入口。
target: 指事件來源對象,點擊嵌套元素最裡層的某元素,該元素就是target。IE6/7/8對應的是srcElement。
currentTarget: 指添加事件handler的元素本身,如el.addEventListener中el就是currentTarget。IE6/7/8沒有對應屬性,可在handler內使用this來替代如evt.currentTarget = this。
relativeTarget: 指事件相關的元素,一般用在mouseover,mouseout事件中。IE6/7/8中對應的是fromElement,toElement。
比如:
當單擊時,彈出當前的id
<input type="button" value="test-豪情" id="test-btn" />
<script type="text/javascript">
$('input').bind('click', function(event){
alert(event.target.id);
});
</script>
 
Jquery中事件重複綁定怎處理???

你可以在給submit綁定事件之前先移除submit上的原有事件
也就是這樣
$("#submit").unbind("click");
$("#submit").click(function(){
你的代碼
});
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.