www.5197.com-澳门新蒲京娱乐场官网

热门关键词: www.5197.com,澳门新蒲京娱乐场官网

Javascript 生成Infiniti下拉列表实今世码_javascript手

[Ctrl A 全选 注:如需引入外部Js需刷新才能执行]

function BindSelect(id,dataList,fieldtext,fieldValue) {
//绑定某一个数据源,fieldtext为需要绑定的文本字段,fieldValue为需要绑定的value字段
var select = $("#" id)[0];
for (var i = 0; i < dataList.length; i ) {
select.options.add(new Option(eval("dataList[" i "]." fieldtext), eval("dataList[" i "]." fieldValue)));
}
}
function BindSelectOptions(id, OptionList) {
var select = $("#" id)[0];
for (var i = 0; i < OptionList.length; i ) {
select.options.add(new Option(OptionList[i].Text, OptionList[i].Value));
}
}
function ClearAllItems(id) {//清空所有的选项
var select = $("#" id)[0];
select.options.length = 0;
}
function AddOneItem(id, text, value) {//添加一个选项
var select = $("#" id)[0];
select.options.add(new Option(text, value));
}
function selectOneOption(id, selectValue) {//根据值,选中一个选项
var select = $("#" id)[0];
var len = select.options.length;
for (var i = 0; i < len; i ) {
if (select.options[i].value == selectValue) {
select.options[i].selected = true;
break;
}
}
}
function selectOneOptionByIndex(id, index) {//<SPAN style="FONT-FAMILY: Arial, Helvetica, sans-serif">//根据下标,选中一个选项</SPAN>

复制代码 代码如下://公司二维数组数据源 Office = [ ["Dept", "ParentDept"], ["业务部", "0"], ["技术部", "0"], ["市场部", "0"], ["www.yongfa365.com", "业务部"], ["业务部小杨", "业务部"], ["业务部小菜", "业务部"], ["技术部老柳", "技术部"], ["技术部老杨", "技术部"], ["技术部老菜", "技术部"], ["市场部柳先生", "市场部"], ["市场部杨先生", "市场部"], ["市场部菜鸟", "市场部"] ] //省市三维数组数据源 City3 = [ ["Dept", "ParentId", "Id"], ["北京", "0", "010"], ["山西", "0", "0359"], ["朝阳区", "010", "001"], ["海淀区", "010", "002"], ["豆各庄", "001", "101"], ["十里堡", "001", "102"], ["中关村", "002", "201"], ["上地", "002", "202"], ["运城地区", "0359", "301"], ["太原市", "0359", "302"], ["永济市", "301", "311"], ["小区", "302", "312"] ]; //FillSelectTree("nowhaha", City3, "0", "311", -1) //Select控件ID,数据源,父级值,选中值,第几级 function FillSelectTree(SelectId, ArrObj, ParentValue, SelectedValue, NowI) { StrObj = eval(document.getElementById; NowI ; //判断它是二级数据源,还是三级 if (ArrObj[0].length == 2) { ArrNum = 0; } else { ArrNum = 2; } //生成所有Option for (var i = 0; i < ArrObj.length; i ) { if (ArrObj[i][1] == ParentValue) { StrObj.options[StrObj.length] = new Option ArrObj[i][0], ArrObj[i][ArrNum]); //选中默认值 if (ArrObj[i][ArrNum] == SelectedValue) { StrObj.options[StrObj.length - 1].selected = true; } //遍历 FillSelectTree(SelectId, ArrObj, ArrObj[i][ArrNum], SelectedValue, NowI); } } } //复制字符串多少次 function String { strtemp = ""; for (var i = 0; i < nowi; i ) { strtemp = str; } return strtemp; }

代码如下: function BindSelect(id,dataList,fieldtext,fieldValue) { //绑定某一个数据源,fieldtext为需要绑定的文本字段,fieldValue为需要绑定的...


var select = $("#" id)[0];
var len = select.options.length;
if (index >= 0 && index <= len) {
select.options[index].selected = true;
}
}

复制代码 代码如下:

本文由www.5197.com发布于服务器运维,转载请注明出处:Javascript 生成Infiniti下拉列表实今世码_javascript手