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("
$("#selectid option").eq(0).attr('selected', 'true');
$("#selectid").val();
9. Get the text of the currently selected item of select
$( "#selectid").text();
10. Get the Index of the currently selected item of select
document.getElementById("select1").selectedIndex;$("#selectid").get(0).selectedIndex
11. Clear the selected item
$("#selectid").empty();
//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 optionfunction jsAddItemToSelect(objSelect, objItemText,objItemValue, objItemPos) {
##if
{ alert(
## }
else ## {
var varItem =
// 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)
);
else
"This item does not exist in the selection" );
}##}
//4. Modify the text of value="paraValue" in the select option to "paraText"
jsUpdateItemToSelect(objSelect, objItemText,objItemValue)
##if
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
{
//Determine whether it exists
isExit =
false; for (
vari=0;i;I++) ## { if (objSelect.options[i].text == objItemText)
## True ; # because
break} ## }
##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
##///7. Get the value of the currently selected item of select
//8. Get the text of the currently selected item of select
//9. Get the Index of the currently selected item of select
//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!