简体   繁体   English

将jquery变量值插入输入隐藏字段

[英]Insert jquery variable value into input hidden field

Insert jquery variable value into input hidden field. 将jquery变量值插入输入隐藏字段。 I am unable to pass variable into hidden field. 我无法将变量传递到隐藏字段。 Basically i have a customize shows page. 基本上我有一个自定义显示页面。 Where i have images related to different materials that we use to make shoes. 我的图像与我们用来制鞋的不同材料有关。 If i click on image to select that material may be a buckle or thread. 如果我点击图片来选择材料可能是带扣或线程。 We get the src of image and insert into hidden field so at the end we submit form with all the images path. 我们得到图像的src并插入隐藏字段,所以最后我们提交所有图像路径的表单。 It's like t-shirt customize page. 这就像T恤定制页面。 Just help me to insert the on click image src into hidden field. 只是帮我将点击图片src插入隐藏字段。

I have code but nothing is working. 我有代码,但没有任何工作。

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);
    });
});

Inserting into hidden input field based on your code 根据您的代码插入隐藏的输入字段

 $(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