[转] 添加option和删除option(兼容IE6、IE7、Firefox2.0)
1
function AddItem( objSelectNow, val, txt ) {
2
var objOption = document.createElement("OPTION");
3
objOption.text = txt;
4
objOption.value = val;
5
objSelectNow.options.add(objOption);
6
}
7
8
function delseloptions() {
9
var obj = document.getElementById('mainbusinessindustry').options;
10
if( obj.length == 0 ) {
11
alert( '没有可删除选项。' );
12
return;
13
}
14
alert( obj[i] );
15
for( var i = 0; i < obj.length; i++ ) {
16
if( obj[i].selected ) {
17
document.getElementById('mainbusinessindustry').remove(i);
18
}
19
}
20
}
function AddItem( objSelectNow, val, txt ) {2
var objOption = document.createElement("OPTION");3
objOption.text = txt;4
objOption.value = val;5
objSelectNow.options.add(objOption);6
}7
8
function delseloptions() {9
var obj = document.getElementById('mainbusinessindustry').options;10
if( obj.length == 0 ) {11
alert( '没有可删除选项。' );12
return;13
}14
alert( obj[i] );15
for( var i = 0; i < obj.length; i++ ) {16
if( obj[i].selected ) {17
document.getElementById('mainbusinessindustry').remove(i);18
}19
}20
}


浙公网安备 33010602011771号