下拉框默認選中第幾條


1.有時候下拉框的值如果是定下來的(往往會有一個空白項)。默認不是空白項的方法為:

var a = document.getElementById("Id");//Id是select 的Id
a.options[1].selected = true;
//或者
$("#mySelect option:first").prop("selected", 'selected');
//或者
 jquery1.6以下版本
$('select').attr('selectedIndex', 1);
 jquery1.6或以上版本
$('select').prop('selectedIndex', 1);
//或者
var SelectArr = $("select")
for (var i = 0; i < SelectArr.length; i++) {
      SelectArr[i].options[0].selected = true; 
  }
 

  

2.獲取下拉框第一條的值:

$("#select_id option:first").val()

  

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM