你的位置:首页 > Java教程

[Java教程]点击文本 自动定位到下拉框选中


 

 

<html >

<head runat="server">
    <title></title>
    <style type="text/css">
        #SiteStat
        {
            width: 97px;
            height: 181px;
        }
    </style>
</head>
<body>
  <from>
  <script language=javascript>
      function foo(){
          //var i = 3;
          var i = document.getElementById("ds").value;
          o = document.getElementById("SiteStat");
          for (c = 0; c < o.length; c++) {
              dy = o.options[c].value.indexOf(i)
            
              if(dy==0)
              //if (o.options[c].value == i)
              {
                  o.options[c].selected = true;
                  break;
              }
          }
      }
</script>

<select name="SiteStat"  multiple="multiple" id="SiteStat">
  <option value="-1" selected></option>
  <option value="1" >状态A</option>
  <option value="0">状态B</option>
  <option value="22">状态C</option>
  <option value="33">状态D</option>
</select>
</from>
<input type='text' name='olala' id='ds'/>
<input type='submit' name='sub' value='查询显示' onclick="foo()"/>
</body>
</html>