开发者

jquery value substitution

开发者 https://www.devze.com 2023-01-17 02:57 出处:网络
Is this a ligitimate way of determining the selected 开发者_开发问答value of an section/option box with and id of \"shirt_size_1221\"?

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

精彩评论

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