误区:
一直以为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;//要的值
【推荐】我凭这三招轻松拿到offer.pdf(吐血整理) >>>
内容来源于网络如有侵权请私信删除
文章来源: 博客园
- 还没有人评论,欢迎说说您的想法!