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;//要的值

posted @ 2020-10-08 12:50  李东平|一线码农  阅读(2609)  评论(0)    收藏  举报