admin 管理员组文章数量: 1086019
$('#id').val() = $.cookie("name");
- not works, nothing changes
document.getElementById('id').value = $.cookie("name");
- works fine
Why?
$('#id').val() = $.cookie("name");
- not works, nothing changes
document.getElementById('id').value = $.cookie("name");
- works fine
Why?
Share Improve this question edited Mar 27, 2011 at 21:54 Diodeus - James MacFarlane 114k33 gold badges163 silver badges180 bronze badges asked Mar 27, 2011 at 21:52 AlexAlex 154 bronze badges4 Answers
Reset to default 8You are not directly accessing the elements value. The left hand side of your expression is a getter which evaluates to a literal. So the expression is parable to something like 5 = 10
, which obviously cant work
$('#id').val() = $.cookie("name");
val()
is overloaded, and by giving it an argument you can reassign
$('#id').val($.cookie("name"));
try to use
$('#id').val($.cookie("name"));
You are using the getter version of val() when you call it with no arguments.
Use $('#id').val($.cookie("name"));
instead.
$('#id').val($.cookie("name"));
本文标签:
版权声明:本文标题:javascript - Why $('#id').val() not working while document.getElementById('id').value works perf 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1743989403a2514443.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论