Home >Web Front-end >JS Tutorial >[IE&FireFox compatible]JS select operation_form effects

[IE&FireFox compatible]JS select operation_form effects

WBOY
WBOYOriginal
2016-05-16 19:22:00961browse

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. :)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn