类似于此:Event binding on dynamically created elements?
但我不是动态地添加元素,而是使用.addClass将类动态地添加到元素中。
基本html:
<div id="WebPartWPQ6_ChromeTitle">
<a accesskey="W" href="/siteurl" >
<span>Access </span></a></div>
功能:
(function($){
$.fn.sharePop = function(){
if(typeof OpenPopUpPage == 'function'){
return this.each(function(i){
if($(this).attr('href') != null){
$(this).click(function(e){
e.preventDefault();
OpenPopUpPage($(this).attr('href'));
});
}
});
}
else{
return false;
}
};
})(jQuery);
$(document).ready(function(){
$('.dialog-pop').sharePop();
});
添加类:
$( document ).ready(function() {
$( "#WebPartWPQ6_ChromeTitle a" ).addClass( "dialog-pop" );
});
这门课加得很好。但我的假设是,当事件连接到元素时,它并不存在--这一行需要改变:
$(this).click(function(e){
我试过这个:
$(this).on('click', '.dialog-pop', function(e){
但没有运气。
发布于 2017-12-10 22:00:17
$(document).on('click',‘.对话框-pop’,函数(){返回函数{代码在这里};});
https://stackoverflow.com/questions/47743890
复制相似问题