1. Determine whether there is an Item with Value="paraValue" in the select option
$("#selectid option[@value='paraValue']").length>0
2. Add an Item
$("#selectid").append("
8. Get the selected The value of the currently selected item
//1. Determine whether there is an Item with Value="paraValue" in the select option
##function jsSelectIsExitItem(objSelect,objItemValue)
{ -
var isExit = false ;
-
for ( var i=0;i;I++)
-
#
##break##;
## isExit; }
-
##//2. Add an Item
to the select option
function jsAddItemToSelect(objSelect, objItemText,objItemValue, objItemPos) {
-
##//Judge whether it exists
##if
(jsSelectIsExitItem(objSelect,objItemValue)) -
{ alert(
- "The Value of this Item already exists"
); ## }
else ## {
-
var varItem =
new
Option(objItemText,objItemValue); // objSelect.options[objSelect.options.length] = varItem; add(varItem, objItemPos); alert( "Joined successfully"
- );
- }
} # #//3. Delete an Item from the select option
##function jsRemoveItemFromSelect(objSelect,objItemValue)
{
//Judge whether it exists
-
if
(jsSelectIsExitItem(objSelect,objItemValue) )
- {
for ( var i=0;i;I++)
{
##if (objSelect.options[i].value == objItemValue)
## ##; ##"Successfully deleted"-
);
-
}
else
-
{
-
alert(
-
"This item does not exist in the selection" );
}
##}
//4. Modify the text of value="paraValue" in the select option to "paraText"
##function jsUpdateItemToSelect(objSelect, objItemText,objItemValue)
{ - //Judge whether it exists
##if
(jsSelectIsExitItem(objSelect,objItemValue)) -
#var
i=0;i;I++)
-
-
if
(objSelect.options[i].value == objItemValue)
-
{# Objselect.options [i] .text = objitemtext; #break
; -
}
#}
# Alert ( ## "Successful modification" );
# { alert( "This select This item does not exist in " );
}
}
-
//5. Set the first Item with text="paraText" in the select to be selected
-
##function
- jsSelectItemByValue(objSelect,objItemText)
{
-
//Determine whether it exists
-
- var
isExit =
false
-
; for (
var
-
i=0;i;I++) ## { if (objSelect.options[i].text == objItemText)
# Objselect.options [i] .select = -
## True ; # because
break
- ;
-
} ## }
- //Show the results
##if
-
(isExit) {
alert ( "Successfully selected"
- );
-
alert( "This item does not exist in this selection"
);
-
}
}
-
##//6. Set the Item with value="paraValue" in select to be selected
##document.all.objSelect.value = objItemValue;
##///7. Get the value of the currently selected item of select
-
- var
currSelectValue = document.all.objSelect.value;
//8. Get the text of the currently selected item of select
- var
currSelectText = document.all.objSelect.options[document.all.objSelect.selectedIndex].text;
//9. Get the Index of the currently selected item of select
- var
currSelectIndex = document.all.objSelect.selectedIndex;
-
//10. Clear the selected items ##document.all.objSelect.options.length = 0 ;
The above is the detailed content of Jquery operation select. For more information, please follow other related articles on the PHP Chinese website!