急 怎样根据下拉框的value获取下拉框的index

解决方案 »

  1.   

    遍历select的所有选项来查找
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <script type="text/javascript">
    function getIndex(oSel, sValue){
    for(var i = 0; i < oSel.options.length; i++){
    if(oSel.options[i].value == sValue){
    return i;
    }
    }
    return -1;
    }
    window.onload = function(){
    var s = document.getElementById("s");
    alert(getIndex(s, "b"));
    };
      </script>
     </HEAD>
     <BODY>
      <select id="s">
    <option value="a">12354</option>
    <option value="b">erewrew</option>
    <option value="c">fdsa</option>
    <option value="d">fdsa</option>
      </select>
     </BODY>
    </HTML>
      

  2.   

    jQuery("input[type=select][id=set]>option:selecd").val();