87,922
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<span style="position:relative">
<select onfocus="this.blur();"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>
<div style="position:absolute;width:100%;height:100%;left:0px;top:0px;background:#fff;opacity:0;filter:alpha(opacity=0)"> </div>
</span>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<span style="position:relative">
<select><option value="1">1</option><option value="2">2</option><option value="3">3</option></select>
<div style="position:absolute;width:100%;height:100%;left:0px;top:0px;background:#fff;opacity:0;filter:alpha(opacity=0)"> </div>
</span>
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function getValue(){
alert("第1个select的值:"+document.getElementById('select1').value);
alert("第2个select的值:"+document.getElementById('select2').value);
}
</script>
</head>
<body>
<div>
<div style="border:solid 1px green;" >
第1种:按原意,不过客户可能还是会有点误会的(能够动,为什么修改不了?)<br />
<select id="select1" onfocus="this.defaultIndex=this.selectedIndex;" onchange="this.selectedIndex=this.defaultIndex;">
<option value="1">test1</option>
<option value="2">test2</option>
<option value="3" selected="selected">test3</option>
<option value="4">test4</option>
<option value="5">test5</option>
</select>
</div>
<div style="border:solid 1px red;" >
第2种:在加载完span和select时,将select2的值给span<br />
<span id="spanSelect2" ></span>
<select id="select2" style="display:none;" >
<option value="1">test1</option>
<option value="2">test2</option>
<option value="3" selected="selected">test3</option>
<option value="4">test4</option>
<option value="5">test5</option>
</select>
<script type="text/javascript">
//在加载完span和select时,将select2的值给span
var select2 = document.getElementById("select2");
var txt = select2.options[select2.selectedIndex].text;
document.getElementById("spanSelect2").innerHTML = txt;
</script>
</div>
<input type="button" onclick="getValue()" value="取得值" />
</div>
</body>
</html>
两种方法,看着办吧。