我有一個錨點標記,當被點擊時顯示更多的項目,顯示那些項目後,另一個錨點出現並再次摺疊這些項目。我有這個腳本在錨標記中的名爲evitd的屬性內搜索字符串,當它發現值觸發警報時,字符串值爲('expand_collapse'),然後顯示更多項並顯示摺疊錨,但腳本不是即使錨點的屬性evtid的值爲'expand_collapse',也可以進行第二次工作。任何建議將讚賞親切jquery停止工作的動態創建元素
$(document).ready(function(){
$('.ms-cal-nav').each(function() {
var $this = $(this);
$this.on("click", function() {
if ($(this).attr('evtid').indexOf('expand_collapse') > -1) {
alert("hello");
}
});
});
});
<div class="ms-acal-ctrlitem" _expand="expand"><a href="javascript:void(0);" class="ms-cal-nav" evtid="expand_collapse"><img border="0" width="9" height="7">7 more items</a></div>
看看事件代表團。 – crush
[動態創建的元素上的事件綁定?]的可能重複?(http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements) – crush