[英]How to add the click attach event dynamically
我需要使用JavaScript動態附加click事件。 我的示例代碼如下。
require(["dijit/form/ToggleButton", "dojo/dom-construct"], function (ToggleButton, domConstruct) {
var newButton = new ToggleButton({
showLabel: true,
checked: false,
onChange: function (val) { frame(this); },
label: item.getAttribute('label')
}, item.getAttribute('id'));
});
如果您使用的是dojo 1.8+,則可以Widget#on
創建窗口小部件后使用Widget#on
連接事件。
var newButton = new ToggleButton({
showLabel: true,
checked: false,
label: item.getAttribute('label')
}, item.getAttribute('id'));
newButton.on('change',function(){
console.log('onChange event called');
});
newButton.on('click',function(){
console.log('click event called');
});
使用button id屬性來附加點擊事件
$("#buttonid").click(function(){
//code goes here
})
其中buttonid是按鈕的id屬性
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.