100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > jquery获取select选中的值

jquery获取select选中的值

时间:2021-04-29 05:08:45

相关推荐

jquery获取select选中的值

误区:

一直以为jquery获取select中option被选中的文本值,是这样写的:

$("#id").text(); //获取所有option的文本值

实际上应该这样:

$("#id option:selected").text(); //获取选中的option的文本值

获取select中option的被选中的value值,

$("#id").val(); //获取选中的值

$("#id option:selected").val();

js获取select选中的值:

var sel=document.getElementById("id");

var index = sel.selectedIndex; // 选中索引

albumid= sel.options[index].value;//要的值

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。