私はこのすべてに非常に慣れていて、JavaScript onclick
機能が付いた画像を複製しようとしています。私はイメージとコーディングを複製して新しいページに配置しましたが、onclick
関数が機能していないようです。しかし、元の作品はちょうどいいです。元のonclick
はモーダルウィンドウを開きますが、複製されたウィンドウは何もしません。JavaScript onclick関数が複製されていますが、元のものだけが機能しますか?
私には何が欠けていますか?
function bump_hype_product(post_id, type_text){
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');
}
});
スクリプトファイルはすべての私のページのヘッダーに表示されている。ここに私のconsumer-global.js
ファイルにある関数である
<img id="product-bump-<?php echo $product->ID; ?>" src="<?php echo get_template_directory_uri();?>/assets_consumer/assets/img/bump-icon_.png" width="20" class="product-arrow" data-toggle="tooltip" data-placement="left" title="Bump" onclick="javascript:bump_hype_product(<?php echo $product->ID; ?>, 'B')" />
:ここ
はonclick
機能を備えた画像です。
あなたのonclickリスナーは、新しく作成されたイメージには適用されません。親要素にリスナーを作成し、クリックのターゲット要素がイメージの場合は、それを複製してください – Gatsbill
ブラウザの開発者ツールのコンソールを開きます。イメージをクリックします。エラーメッセージの内容を見てください。 – Quentin