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 badges
Add a ment  | 

4 Answers 4

Reset to default 8

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 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"));

本文标签:

Error[2]: Invalid argument supplied for foreach(), File: /www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm, Line: 58
File: /www/wwwroot/roclinux.cn/tmp/route_read.php, Line: 205, include(/www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm)
File: /www/wwwroot/roclinux.cn/tmp/index.inc.php, Line: 129, include(/www/wwwroot/roclinux.cn/tmp/route_read.php)
File: /www/wwwroot/roclinux.cn/index.php, Line: 29, include(/www/wwwroot/roclinux.cn/tmp/index.inc.php)