簡體   English   中英

將jquery變量值插入輸入隱藏字段

[英]Insert jquery variable value into input hidden field

將jquery變量值插入輸入隱藏字段。 我無法將變量傳遞到隱藏字段。 基本上我有一個自定義顯示頁面。 我的圖像與我們用來制鞋的不同材料有關。 如果我點擊圖片來選擇材料可能是帶扣或線程。 我們得到圖像的src並插入隱藏字段,所以最后我們提交所有圖像路徑的表單。 這就像T恤定制頁面。 只是幫我將點擊圖片src插入隱藏字段。

我有代碼,但沒有任何工作。

jQuery(document).ready(function() {
    jQuery('.pro_img').click(function() {
        var $pro_class = $('.pro_img');
        $pro_class.removeClass('pic_select');
        $(this).addClass('pic_select');

        var imgpro = jQuery(this).attr('src');
        document.getElementById('hidden_pro_image').value = imgpro;
        //$('#hidden_pro_image').val(imgpro);

        alert(imgpro);
    });
});

根據您的代碼插入隱藏的輸入字段

 $(document).ready(function() { $('.pro_img').click(function() { var imgpro = jQuery(this).attr('src'); $('#hidden_pro_image').val(imgpro); alert($('#hidden_pro_image').val()); }); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <img class="pro_img" src="https://i0.wp.com/wptavern.com/wp-content/uploads/2016/07/stack-overflow.png?ssl=1" width="100px" /> <input id="hidden_pro_image" type="hidden" value="" /> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM