復制代碼 代碼如下:
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>
var select = $("#" + id)[0];
var len = select.options.length;
if (index >= 0 && index <= len) {
select.options[index].selected = true;
}
}