複製代碼代碼如下:
<html>
<頭>
<腳本類型=“ text/javascript”>
函數showdiv(id){
document.getElementById(“ selectOption”)。 style.display =“ block”;
document.getElementById(“ selectOption”)。樣式position =“ absolute”;
document.getElementById(“ selectOption”)。 style.top = document.getElementById(id).offsetTop+25;
document.getElementById(“ selectOption”)。 style.left = document.getElementById(id).offsetleft+20;
}
函數selectm()
{
var obj = document.getElementById(“ mySelect”);
警報(obj.SelectedIndex);
}
函數checkSelect(objname){
o = document.getElementById(objname);
t = document.getElementById(“輸出”);
var intvalue =“”;
for(i = 0; i <o.length; i ++){
如果(o.options [i] .selected){
intvalue+= o.options [i] .value+“,”;
}
}
t.value = intvalue.substr(0,intvalue.length-1);
警報(Intvalue);
}
</script>
</head>
<身體>
<形式>
<div id =“ selectoption” style ='寬度:100px;高度:50px; z-index:100; border:1px solid#0099ff;背景:#ccccccccccccccc; display:none;'>'>
<select id =“ mySelect” protive =“多=” size =“ 4”>
<option value ='蘋果'>蘋果</option>
<option value ='桃子'>桃子</option>
<option value ='香蕉'>香蕉</option>
<option value ='桔子'>桔子</option>
</select>
<input type =“ button” onclick =“ checkSelect('mySelect')” value =“ checkSelect”>
</div>
選中的項目:<input type =“ text” name =“輸出”>
<輸入id =“ lalla” type =“ button” onclick =“ showdiv(this.id)” value =“選擇”>
<br/>
</form>
<p>在您點擊“選擇多個”,請嘗試同時選取多個選項。在點擊,“選擇多個”,請再試一次。 </p>
</form>
</body>
</html>