jQuery access input hidden value

前端 未结 9 1897
执念已碎
执念已碎 2020-11-28 01:50

How can I access tag\'s value attribute using jQuery?

9条回答
  •  余生分开走
    2020-11-28 02:51

    Watch out if you want to retrieve a boolean value from a hidden field!

    For example:

    
    

    (An input like this will be rendered by ASP MVC if you use @Html.HiddenFor(m => m.SomeBoolean).)

    Then the following will return a string 'False', not a JS boolean!

    var notABool = $('#SomeBoolean').val();
    

    If you want to use the boolean for some logic, use the following instead:

    var aBool = $('#SomeBoolean').val() === 'True';
    if (aBool) { /* ...*/ }
    

提交回复
热议问题