$.fn.fillSelect = function (data) {
return this.clearSelect().each(function() {
if (this.tagName == 'SELECT') {
var dropdownList = this;
$.each(data, function (index, optionData) {
var option = new Option(optionData.Text, optionData.Value);
if ($.browser.msie) {
dropdownList.add(option);
} else {
dropdownList.add(option, null);
}
});
// code for access "selectedindex"
}
});
};
以上是使用jQuery動態生成下拉列表的代碼片段。下拉框selectedIndex屬性
我需要動態設置selectedIndex屬性值,以便更早地顯示保存的值。我將在上面的代碼中插入該代碼到// code for access "selectedindex"
的地方。那麼我怎樣才能爲dropdownList
設置selectedIndex屬性?
你想設置或獲取selectedIndex? – 2013-03-12 11:23:22
@Olylyodgson設置selectedIndex。 – Sampath 2013-03-12 11:24:08