Home >Web Front-end >JS Tutorial >JavaScript operation select reference code_javascript skills
1. Determine whether there is an Item with Value="paraValue" in the select option. < objSelect.options .length; i ) {
}
2. Add an Item to the select option
function jsAddItemToSelect(objSelect, objItemText, objItemValue) { 🎜> if (jsSelectIsExitItem(objSelect, objItemValue )) { 🎜> ObjSelect.options.add(varItem) ; ;
alert("Successfully joined"); , objItemValue) { /Determine whether it exists If (objSelect.options[i] .value == objItemValue) { 🎜> alert("This item does not exist in the selection");
4. Delete the selected item in select
function jsRemoveSelectedItemFromSelect(objSelect) { var length = objSelect.options.length - 1;
for(var i = length; i >= 0; i--){
if(objSelect[i].selected == true){
objSelect.options[i] = null; }
}
5. Modify the text of value="paraValue" in the select option to "paraText" 🎜> if ( jsSelectIsExitItem(objSelect, objItemValue)) { == objItemValue) {
; The item does not exist in "); "
} " "
} " " {
//Determine whether it exists
var isExit = false;
for (var i = 0; i < objSelect.options.length; i ) {
if (objS elect.options[i]. text == objItemText) { > if (isExit) { }
}
7. Set the Item with value="paraValue" in the select to be selected
document.all.objSelect.value = objItemValue;
8. Get the current selection of the select The value of the item
var currSelectValue = document.all.objSelect.value;
9. Get the text of the currently selected item of select
var currSelectText = document.all.objSelect.options[document.all .objSelect.selectedIndex].text;
10. Get the Index of the currently selected item of select
var currSelectIndex = document.all.objSelect.selectedIndex;
11. Clear the selected item
document.all.objSelect.options.length = 0;
The above is collected from the Internet, now look at what is done based on the above content