Set value of hidden input with jquery

前端 未结 7 913
忘了有多久
忘了有多久 2020-12-25 09:03

I\'m trying to set the value of the hidden field below using jQuery.


I\'m using

相关标签:
7条回答
  • 2020-12-25 09:46
    $('input[name="testing"]').val(theValue);
    
    0 讨论(0)
  • 2020-12-25 09:47

    Suppose you have a hidden input, named XXX, if you want to assign a value to the following

    <script type="text/javascript">
    
        $(document).ready(function(){
        $('#XXX').val('any value');
        })
    </script>
    
    0 讨论(0)
  • 2020-12-25 09:56

    You should use val instead of value.

    <script type="text/javascript" language="javascript">
    $(document).ready(function () { 
        $('input[name="testing"]').val('Work!');
    });
    </script>
    
    0 讨论(0)
  • 2020-12-25 09:57

    To make it with jquery, make this way:

    var test = $("input[name=testing]:hidden");
    test.val('work!');
    

    Or

    var test = $("input[name=testing]:hidden").val('work!');
    

    See working in this fiddle.

    0 讨论(0)
  • 2020-12-25 09:59
    var test = $('input[name="testing"]:hidden');
    test.val('work!');
    
    0 讨论(0)
  • 2020-12-25 10:03

    This worked for me:

    $('input[name="sort_order"]').attr('value','XXX');
    
    0 讨论(0)
提交回复
热议问题