Why $('#id').val() not working while document.getElementById('id').value works perfect?
$('#id').val() = $.cookie("name"); - not works, nothing cha开发者_如何学Cnges
document.getElementById('id').value = $.cookie("name"); - works fine
Why?
You 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 comparable 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"));
加载中,请稍侯......
精彩评论