Home >Web Front-end >JS Tutorial >[IE&FireFox compatible]JS select operation_form effects
Today, I used two drop-down boxes in Ajax to dynamically add options in the select. When I tested it, it worked normally in IE but not in FireFox. I was not very familiar with scripts, so I checked online and found that they were adding them dynamically. option is a little different.
Write it down below, maybe you can use it in the future:
Dynamically delete all options in the select:
function deleteAllOptions(sel){
sel.options. length=0;
}
Dynamically delete an option in the select:
function deleteOption(sel,indx){
sel.options.remove(indx);
}
Dynamically add item option in select:
function addOption(sel,text,value){
sel.options.add(new Option(text,value));
}
The above can be tested successfully in IE and FireFox. I hope you can use it in the future.
In fact, standard DOM operations can also be used, such as document.createElement, appendChild, removeChild and the like. :)