1)select的隐藏和显示:
$("selectList").style.display=$("selectList").style.display=="block"?"none":"block";
2)select可用不可用:
<selectdisabled="value">
document.getElementById("LevelDropList").disabled="value";不可用
document.getElementById("LevelDropList").disabled="value";可用
<html>
<head>
<SCRIPTLANGUAGE="JavaScript">
<!--
//oSelect列表的底部添加了一个新选项
functiononload(){
varoOption=document.createElement("OPTION");
oOption.text="Ferrari";
oOption.value="4";
oSelect.add(oOption);
}
functionfnChange(){
oData.value+=oCars.options[oCars.selectedIndex].text+"";
}
//-->
</SCRIPT>
</head>
<bodyonload="onload()"><!--手工添加一个Select-->
<!--1usestheSELECTelementtocreateadrop-downlistbox-->
<SELECTNAME="Cats"SIZE="1">
<OPTIONVALUE="1">Calico
<OPTIONVALUE="2">Tortie
<OPTIONVALUE="3"SELECTED>Siamese
</SELECT>
<P>
<!--2select元素创建了多项选择列表框,方法是设置了SIZE和MULTIPLE标签属性。要获得多项选择列表框的选中选项,则须遍历options集合并检查SELECTED是否被设为true。-->
<SELECTID="oSelect"NAME="Cars"SIZE="3"MULTIPLE><!--此处设置了3和multiple-->
<OPTIONVALUE="1"SELECTED>BMW
<OPTIONVALUE="2">Porsche
<OPTIONVALUE="3"SELECTED>Mercedes
</SELECT>
<P>
<!--3以下演示Option的用法-->
<SELECTID="oCars"SIZE="1"onchange="fnChange()">
<OPTIONVALUE="1">宝马
<OPTIONVALUE="2">保时捷
<OPTIONVALUE="3"SELECTED>大奔
</SELECT>
<P>
<TEXTAREAID="oData"></TEXTAREA>
</body>
</html>
附:一些Select的技巧
1.动态创建select
functioncreateSelect(){
varmySelect=document.createElement("select");
mySelect.id="mySelect";
document.body.appendChild(mySelect);
}
2.添加选项option
functionaddOption(){
//根据id查找对象,varobj=document.getElementById('mySelect');
//添加一个选项obj.add(newOption("文本","值"));}
3.删除所有选项option
functionremoveAll(){
varobj=document.getElementById('mySelect');
obj.options.length=0;
}
4.删除一个选项option
functionremoveOne(){
varobj=document.getElementById('mySelect');
//index,要删除选项的序号,这里取当前选中选项的序号
varindex=obj.selectedIndex;
obj.options.remove(index);
}
5.获得选项option的值
varobj=document.getElementById('mySelect');
varindex=obj.selectedIndex;//序号,取当前选中选项的序号
varval=obj.options[index].value;
6.获得选项option的文本
varobj=document.getElementById('mySelect');
varindex=obj.selectedIndex;//序号,取当前选中选项的序号
varval=obj.options[index].text;
7.修改选项option
varobj=document.getElementById('mySelect');
varindex=obj.selectedIndex;//序号,取当前选中选项的序号
varval=obj.options[index]=newOption("新文本","新值");
8.删除select
functionremoveSelect(){
varmySelect=document.getElementById("mySelect");
mySelect.parentNode.removeChild(mySelect);
}
9.设置selectoptin被中
functionremoveSelect(){
//向办件人员下拉列表动态添加员工
for(vari=0;i<json.length;i++){
varnewOption=newOption(json[i].empname,json[i].empid,i);
//向办件人员下拉列表添加员工信息
objDeal.options.add(newOption);
//客户业务员的Id不为空
if(empbyDealEmpId!=""||empbyDealEmpId!=0){
//员工id等于下拉列表中的值,则下拉列表被选中
if(empbyDealEmpId==objDeal.options[i].value){
//判断此下拉列表被选中
objDeal.options[i].selected=true;


本文转载自中文网


本文转载自中文网
如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html5/h54938.shtml