HTML中Select的使用具体解释

2020-12-13 20:18

阅读:405

YPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">

 



function fnChange(){
oData.value+=oCars.options[oCars.selectedIndex].text + " ";
}

//-->










附:一些Select的技巧

1.动态创建select

function createSelect(){

var mySelect = document.createElement("select"); 
mySelect.id = "mySelect"; 
document.body.appendChild(mySelect);
}

2.加入选项option

function addOption(){

//依据id查找对象,
var obj=document.getElementById(‘mySelect‘);

//加入一个选项
obj.add(new Option("文本","值")); 
}

3.删除全部选项option

function removeAll(){
var obj=document.getElementById(‘mySelect‘);

obj.options.length=0;

}

4.删除一个选项option

function removeOne(){
var obj=document.getElementById(‘mySelect‘);

//index,要删除选项的序号,这里取当前选中选项的序号

var index=obj.selectedIndex;
obj.options.remove(index);
 
}

5.获得选项option的值

var obj=document.getElementById(‘mySelect‘);

var index=obj.selectedIndex; //序号,取当前选中选项的序号

var val = obj.options[index].value;

6.获得选项option的文本

var obj=document.getElementById(‘mySelect‘);

var index=obj.selectedIndex; //序号,取当前选中选项的序号

var val = obj.options[index].text;

7.改动选项option

var obj=document.getElementById(‘mySelect‘);

var index=obj.selectedIndex; //序号,取当前选中选项的序号

var val = obj.options[index]=new Option("新文本","新值");

8.删除select

function removeSelect(){
var mySelect = document.getElementById("mySelect");
mySelect.parentNode.removeChild(mySelect);
}

9.设置select optin被中

function removeSelect(){
// 向办件人员下拉列表动态加入员工
for ( var i = 0; i var newOption = new Option(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;
}
}
}
}

1soscw.com,搜素材1 检測是否有选中 2soscw.com,搜素材soscw.com,搜素材if(objSelect.selectedIndex > -1) soscw.com,搜素材{ 3soscw.com,搜素材//说明选中 4soscw.com,搜素材soscw.com,搜素材} else soscw.com,搜素材{ 5soscw.com,搜素材//说明没有选中 6soscw.com,搜素材} 7soscw.com,搜素材 8soscw.com,搜素材2 删除被选中的项 9soscw.com,搜素材objSelect.options[objSelect.selectedIndex] = null;10soscw.com,搜素材11soscw.com,搜素材3 添加项12soscw.com,搜素材objSelect.options[objSelect.length] = new Option("你好","hello");13soscw.com,搜素材14soscw.com,搜素材4 改动所选择中的项15soscw.com,搜素材objSelect.options[objSelect.selectedIndex] = new Option("你好","hello");16soscw.com,搜素材17soscw.com,搜素材5得到所选择项的文本18soscw.com,搜素材objSelect.options[objSelect.selectedIndex].text;19soscw.com,搜素材20soscw.com,搜素材6 得到所选择项的值21soscw.com,搜素材objSelect.options[objSelect.selectedIndex].value;22soscw.com,搜素材


评论


亲,登录后才可以留言!