[英]Is there a Mootools “.on” equivalent?
我正在Mootools中尋找與jQuery等效的.on()
。 目的是將事件動態綁定到用戶交互后附加到頁面的元素。
有addEvent()
和addEvents()
方法將事件偵聽器附加到DOM元素。 檢查http://mootools.net/docs/core/Element/Element.Event中的文檔。
這是頁面上的示例:
// Get the element, add a click listener...
document.getElementById("parent-list").addEventListener("click",function(e) {
// e.target is the clicked element!
// If it was a list item
if(e.target && e.target.nodeName == "LI") {
// List item found! Output the ID!
console.log("List item ",e.target.id.replace("post-")," was clicked!");
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.