开发者

jquery value substitution

Is this a ligitimate way of determining the selected 开发者_开发问答value of an section/option box with and id of "shirt_size_1221"?

var user_id = '1221';
x = "#shirt_size_" + user_id ;                          
alert($(x + " option:selected"));


Your alert statement will always show [object] unless you change it to

alert($(x+' option:selected').val());

And don't worry, this is a good way of getting selected option.


You can get the value of a selected option in a dropdown box by using

var selectList = document.getElementById("shirt_size_1221");
var val = selectList.options[selectList.selectedIndex].text;

No JQuery needed.


The "proper" way is simply:

var user_id = '1221';
x = "#shirt_size_" + user_id ;        
alert($(x).val());
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜