admin管理员组文章数量:1322838
I have a hidden field in my page like so:
<hidden id="tsDaySchedule01" value="7.50"></hidden>
When I try to access it with the following code, the alert returns blank:
alert($("#tsDaySchedule01").val());
Now when I use attr("value")
like below, it works without issue:
alert($("#tsDaySchedule01").attr("value"));
Lastly, I would like to point out we have other non-hidden text fields within the page that work without issue using val()
.
I would like to have a better understanding as for what is going on here. Does anybody have an explanation?
I have a hidden field in my page like so:
<hidden id="tsDaySchedule01" value="7.50"></hidden>
When I try to access it with the following code, the alert returns blank:
alert($("#tsDaySchedule01").val());
Now when I use attr("value")
like below, it works without issue:
alert($("#tsDaySchedule01").attr("value"));
Lastly, I would like to point out we have other non-hidden text fields within the page that work without issue using val()
.
I would like to have a better understanding as for what is going on here. Does anybody have an explanation?
Share Improve this question edited Oct 29, 2013 at 18:30 James Donnelly 129k35 gold badges214 silver badges223 bronze badges asked Oct 7, 2013 at 13:48 Code JunkieCode Junkie 7,78827 gold badges86 silver badges147 bronze badges 2-
Where did you found this
hidden
tag ? oO – Brewal Commented Oct 7, 2013 at 13:52 - @Brewal the framework is a tag based language that typically converts the elements to their proper format, the problem had to do with me removing the namespace for the framework and forgetting to change the field. Thanks Everyone. – Code Junkie Commented Oct 7, 2013 at 14:03
3 Answers
Reset to default 8<hidden/>
isn't a valid HTML element. If you're wanting a hidden input you'd use:
<input type="hidden" />
jQuery's .val()
method only works on input
, select
and textarea
elements. To get this to work for you, change your <hidden/>
element to:
<input type="hidden" id="tsDaySchedule01" value="7.50" />
.val() method only works with text-box type of element input
and textarea
elements.
you should use
<input type='hidden' id="tsDaySchedule01" value="7.50">
Maybe you need to use :
<input type='hidden' id="tsDaySchedule01" value="7.50">
本文标签: javascriptjQuery39s val() is not working on a hidden fieldStack Overflow
版权声明:本文标题:javascript - jQuery's val() is not working on a hidden field - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742116692a2421500.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论