我们在做网页的时候,有时候会需要一个可以接受输入的列表框,但是html中的<select>元素不能达到这个功能
有一个方法就是用activeX控件,但这样虽然很方便,有些人却不喜欢……^_^
方法如下:
<form>
<OBJECT classid=clsid:8BD21D30-EC42-11CE-9E0D-00AA006002F3 id=MdcCombo1 name=MdcCombo1 VIEWASTEXT>
<PARAM NAME="VariousPropertyBits" VALUE="746604571">
<PARAM NAME="BackColor" VALUE="2147483653">
<PARAM NAME="ForeColor" VALUE="2147483656">
<PARAM NAME="MaxLength" VALUE="0">
<PARAM NAME="BorderStyle" VALUE="0">
<PARAM NAME="ScrollBars" VALUE="0">
<PARAM NAME="DisplayStyle" VALUE="3">
<PARAM NAME="MousePointer" VALUE="0">
<PARAM NAME="Size" VALUE="2540;635">
<PARAM NAME="PasswordChar" VALUE="0">
<PARAM NAME="ListWidth" VALUE="0">
<PARAM NAME="BoundColumn" VALUE="1">
<PARAM NAME="TextColumn" VALUE="65535">
<PARAM NAME="ColumnCount" VALUE="1">
<PARAM NAME="ListRows" VALUE="8">
<PARAM NAME="cColumnInfo" VALUE="0">
<PARAM NAME="MatchEntry" VALUE="1">
<PARAM NAME="ListStyle" VALUE="0">
<PARAM NAME="ShowDropButtonWhen" VALUE="2">
<PARAM NAME="ShowListWhen" VALUE="1">
<PARAM NAME="DropButtonStyle" VALUE="1">
<PARAM NAME="MultiSelect" VALUE="0">
<PARAM NAME="Value" VALUE="">
<PARAM NAME="Caption" VALUE="">
<PARAM NAME="PicturePosition" VALUE="458753">
<PARAM NAME="BorderColor" VALUE="2147483654">
<PARAM NAME="SpecialEffect" VALUE="2">
<PARAM NAME="Accelerator" VALUE="0">
<PARAM NAME="GroupName" VALUE="">
<PARAM NAME="FontName" VALUE="Times New Roman">
<PARAM NAME="FontEffects" VALUE="1073741824">
<PARAM NAME="FontHeight" VALUE="240">
<PARAM NAME="FontOffset" VALUE="0">
<PARAM NAME="FontCharSet" VALUE="0">
<PARAM NAME="FontPitchAndFamily" VALUE="34">
<PARAM NAME="ParagraphAlign" VALUE="1">
<PARAM NAME="FontWeight" VALUE="400">
</OBJECT>
</form>
<script>
function loaditem(){
with(document.all.MdcCombo1){
AddItem("aaaaaa")
AddItem("bbbbbb")
AddItem("cccccc")
AddItem("dddddd")
AddItem("eeeeee")
AddItem("ffffff")
}
}
document.onload=loaditem
</script>
但是select元素配合css/javascript真的不可以达到这个效果吗?
答案是肯定的,至少也能模拟出类似效果
显然是可以把一个文本框独立层放在<select>之上,盖住<select>内容
然后在select元素的onchange中赋值给文本框,然后提交文本框内容……
呵呵,很简单呀——但是这样一做来看就傻眼了(具体你自个琢磨)
那么我们就要加上css这个强大工具:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<select name="select"style="position:absolute; left: 0px; top: 0px; width: 120px; height: 18px; clip: rect(0 120 18 100)" id="select" onchange="textfield.value=select.value;textfield.select()">
<option value="aaaaaaaa">aaaaaaaa</option>
<option value="bbbbbbbb">bbbbbbbb</option>
<option value="cccccccc">cccccccc</option>
</select>
<input type="text" style="position:absolute; left: 0px; top: 0px; width: 100px; height: 18px" name="textfield">
</body>
</html>
不是很完善,留给看众完善了……呵呵