請問這是什么問題,是事件冒泡造成的嗎?
//添加jQuery模塊依賴
require.config({//require自帶config方法可以把文件名和映射的模塊名相關聯
paths:{jquery:'jquery.min',
jqueryUI:'jquery-ui.min'
}
});
require(['jquery','window'],function($,w){
$("#a").click(function(){
var win=new w.Window().alert({
title:"提示",
content:"welcome!",
handler:function(){
alert("You click the button");
},
width:300,
height:150,
y:50,
hasCloseBtn:true,
text4AlertBtn:"OK",
dragHandle:".window_header",
skinClassName:"window_skin_a",
handler4AlertBtn:function(){
alert("you click the alert button");
},
handler4CloseBtn:function(){
alert("you click the close button");
}
}).on("alert",function(){
alert("the second alert handler");
}).on("close",function(){
alert("the second close handler");
});
win.on("alert",function(){
alert("the third alert handler");
});
});
});
如上述代碼瑣示,除了自己加了皮膚skinClassName這個參數外其余和老師一模一樣
問題出現在:
handler4AlertBtn:function(){
alert("you click the alert button");
},
handler4CloseBtn:function(){
alert("you click the close button");
}
當點擊alert(OK按鈕)時,出現了:you click the alert button ,you click the alert button,the second alert handler,the third alert handler看似和老師的一樣但是明顯的是you click the alert button多出現了1次,同樣當點擊關閉(close)按鈕時也出現了:you click the close button,you click the close button,the second close handler即多出現了一次you click the close button,請問是什么原因?
2017-02-03
調用了兩次