[英]onclick event on dynamic element not working
i am trying to attach an event listener to a static element to allow onclicks on my dynamic images to work. 我正在尝试将事件侦听器附加到静态元素,以允许对动态图片进行onclicks操作。 I cannot for the life of me seem to achieve this.
我似乎无法实现这一目标。 I have repeatedly searched and copied the answers in other posts but to no avail.
我已经反复搜索并复制了其他帖子中的答案,但无济于事。
I'm not sure what im doing wrong, whether it be a bug in my code or that im just missing something all together. 我不确定我做错了什么,无论是我的代码中的错误还是我只是一起丢失了一些东西。
Any help would be appreciated, below is my code: 任何帮助将不胜感激,以下是我的代码:
$(document).on('click','.newsfeed-bump',function(bump_hype_product){
jQuery('#product-message-confirmation-wrap').hide();
jQuery('.popup-waiting-wrap').show();
jQuery('#modal_product_message_confirmation h4.modal-title').html('');
jQuery.ajax({
url : the_ajax_script.ajaxurl,
type : 'post',
data : {
action : 'bump_hype_product',
type : type_text,
post_id : post_id
},
success : function( response ) {
jQuery('.popup-waiting-wrap').hide();
jQuery('#product-message-confirmation-wrap').show();
jQuery('#product-message-confirmation-wrap').html(response);
jQuery('#modal_product_message_confirmation').modal('show');
}
});
});
Im getting "Uncaught ReferenceError: type_text is not defined" 我正在收到“未捕获的ReferenceError:未定义type_text”
please try this: 请尝试以下操作:
$('#document').on('click','.newsfeed-bump',bump_hype_product,function(){
// your logic
}
Use this 用这个
$("body").delegate(".newsfeed-bump", "click", function(){
//your code
});
or 要么
$("body").on("click", ".newsfeed-bump" function(){
//your code
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.