下拉框:
<select id="selectID" >
<option value="1">1option>
<option value="2">2option>
<option value="3">3option>
<option value="4">4option>
<option value="5">5option>
<option value="6">6option>
select>
下面是对下拉框的基本操作:
<#script language="javascript ">
//Bind the drop-down box change
event, and call the SelectChange() method when the drop-down box changes"
#selectID").change(function() { SelectChange(); }); SelectChange() { //Get the text attribute
value of the selected item in the drop-down box
# # var selectText = $("
#selectID").find( "option:selected").text(); alert(selectText); //Get the value attribute of the selected item in the drop-down box
## var selectValue
= $ ("
#selectID").val(); alert(selectValue); //Get the index attribute value of the selected item in the drop-down box## var selectIndex
= $ ("#selectID
").get(0).selectedIndex; alert(selectIndex); ////Get the maximum index attribute value of the drop-down box var selectMaxIndex
= $("#selectID option:last
").attr("index"); alert(selectMaxIndex) ; } function aa() { ## $("#selectID").get(0).selectedIndex = 5;
}
function bb() (
"#selectID"
).val(4); } function cc() { // Set the option of setting the text attribute of the drop-down box to 5 and select
$(
"#selectID option[text=5]"
).attr("selected", "selected");").attr("
",
true); }
function dd() {
//Add an option at the end of the drop-down box
$("#selectID").append("");
}
function ee() {
//Add an option at the front of the drop-down box
## ##selectID").prepend("") } function ff() {
//
Remove the last item in the drop-down box Option $(
"#selectID option:last") .remove(); } function gg() {
//
Remove the option with the index attribute of 1 in the drop-down box $(
"#selectID option[index=1]"). remove(); } function hh() {
//
Remove the option with the value attribute of 4 in the drop-down box $(
"#selectID option[value=4]").remove (); } function ii() {
//
Remove the option with the text attribute of 5 in the drop-down box $(
"#selectID option[text=5]").remove(); }
script>
The above is the detailed content of JQuery operation on Select option. For more information, please follow other related articles on the PHP Chinese website!