Can't set hidden input field's value using jQuery

前端 未结 11 1766
耶瑟儿~
耶瑟儿~ 2020-12-29 02:45

I have a simple input field inside a form tag:


  
11条回答
  •  情深已故
    2020-12-29 03:05

    I've confirmed that setting the value of a hidden field does not work with a jQuery selector like this...

    $('[name="my_field"]').val('Something');
    

    Will not update a hidden field... kinda shocking.

    
    

    Was forced to use a CSS hidden field instead.

    
    

    Apparently there are other issues with using the id of a hidden field as well... Set value of hidden field in a form using jQuery's ".val()" doesn't work

    Note: be sure to obtain the value in the console and not by inspecting.

    $('[name="my_field"]').val();
    

提交回复
热议问题