开发者

Why do I get nothing with $('#leftquota').val()?

<span id="leftquota" style="display:none" value="$row[available]">$row[available]</span>

JQuery code:

var left=$('#leftquota')开发者_如何学Go.val();
alert(left);


var left=$('#leftquota').attr('value'); alert(left);

is what you want.

The .attr() method gets(or sets) an attribute of a element. So .attr('value') will get the value of the 'value' attribute.

EDIT: As morning coffee pointed out, the same value of the 'value' attribute is given inside the span.

So we should do

var left=$('#leftquota').text(); alert(left);

to get the value.

Also, 'value' is not a valid attribute for the span tag.


Because val() takes the value from an input field. value is not a valid attribute of <span>.

You should use .text() since you store the same information as in the value-field inside your <span>.

Example:

var left = $('#leftquota').text();
alert(left);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜