Javascript ~ set Select Index by Value

最近蠻常用到這程式的說~~自己寫的~XD

function setSelectIndexByValue(e, value)
{
 for(var x in e.options)
 {
  if(e.options[x].value == value)
  {
   e.selectedIndex = x;
  }
 }
 
}

--------------------------------------------------------------------------------------------

var selectObject = document.getElementById('selectObject');
var value = 'qqqqqqqqqq';

setSelectIndexByValue(selectObject , value);

沒有留言: