日期:2014-05-16  浏览次数:20391 次

js javascript <select>根据value或text设置下拉列表的默认值
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
 
 </HEAD>

 <BODY>
  <select name="actorname" id="actor">
	<option value="all">全部</option>
	<option value="hstf">黑色头发</option>
	<option value="zstf">紫色头发</option>
	<option value="bj">北京</option>
	<option value="hjyy">海军医院</option>
	<option value="kjyy">空军医院</option>
	<option value="ljyy">陆军医院</option>
  </select>&nbsp;&nbsp;&nbsp; &nbsp;
 </BODY>
  <script>
function selectValue(sId,value){
    var s = document.getElementById(sId);
    var ops = s.options;
    for(var i=0;i<ops.length; i++){
		var tempValue = ops[i].value;
		if(tempValue == value)
		{
			ops[i].selected = true;
		}
    }
}

selectValue('actor','hstf');
  </script>
</HTML>


黑色头发:http://heisetoufa.iteye.com
1 楼 Bucher03 2011-08-12  
sgip wq r p hxf ftjb i thtc tf kb ,lz js onr sb b !
2 楼 王向众 2011-09-14  
太强悍了您!