Home > Article > Web Front-end > jquery operation select encyclopedia
This article mainly introduces the methods and examples used in jquery operation select. Friends in need can refer to the following
Add option
Copy code The code is as follows:
$('#id').append("");// Append an option
$('#id').prepend(""); //Insert an option
Remove option
Copy code The code is as follows:
$("#ID option"). each(function(){
if($(this).val()==111){
$(this).remove();
}
});
$("").appendTo($("#ID"));
Get the selection value of the drop-down menu
$( "#testSelect option:selected").text();
$("#testSelect").find('option:selected').text();
$("#testSelect").val( );
Select the drop-down box according to the value of option
$('#testSelect').val('111');
2, radio button:
Copy code The code is as follows:
$("input[@type=radio][@checked]").val();//Get the radio button selected The value of the item (note that there is no space in the middle)
$("input[@type=radio][@value=2]").attr("checked",'checked');//Set the radio button value= 2 is the selected state. (note that there is no space in the middle)
3,checkbox:
$("input[@type=checkbox][@checked] ").val();//Get the value of the first selected item of the check box
$("input[@type=checkbox][@checked]").each(function(){//Due to Generally, multiple check boxes are selected, so you canloopoutput
alert($(this).val());
});
$(" #chk1").attr("checked",'');//Unchecked
$("#chk2").attr("checked",true);//Checked
if($ ("#chk1").attr('checked')==undefined){}//Determine whether it has been checked
Of course jquery's selector is powerful. There are many ways.
Copy code The code is as follows:
jquery radio value, checkbox value, select value, radio selection, checkbox selection, select selection, and related acquisition of a set of radio selected item values
Copy code The code is as follows:
varitem= $('input[@name=items][@checked]').val() ;
Get the text of the selected item
Copy code The code is as follows:
varitem= $( "select[@name=items] option[@selected]").text();
select The second element of the drop-down box is the currently selected value
Copy code The code is as follows:
$('#select_id')[0].selectedIndex=1;
The number of the radio radio group The two elements are the currently selected values
Copy code The code is as follows:
$('input[@name=items]').get (1).checked=true;
Get value:
Text box, text area:
Copy code The code is as follows:
$("#txt" ).attr("value");
Multiple selection box checkbox:
Copy code The code is as follows:
$("#checkbox_id").attr("value");
Single selection group radio:
Copy code The code is as follows :
$("input[@type=radio][@checked]").val();
Drop-down box select:
Copy code The code is as follows:
$('#sel').val();
Control form elements:
Text box, text area:
Copy code The code is as follows:
$("#txt").attr("value", '');//Clear the content
$("#txt").attr("value",'11');//Fill the content
Multiple selection box checkbox:
Copy code The code is as follows:
$("#chk1").attr("checked",'');//Uncheck
$("#chk2").attr("checked",true);//Tick
if($("#chk1").attr('checked')==undefined)//Judgment Whether it has been checked
Radio group radio:
$("input[@type=radio]").attr("checked",'2');//Set value= The item 2 is the currently selected item
drop-down box select:
Copy code The code is as follows:
$("#sel") .attr("value",'-sel3');//Set the item with value=-sel3 as the currently selected item
$("
$("#sel").empty();//Clear the drop-down box
Get the value of a group of radio selected items
Copy code The code is as follows:
varitem= $('input [@name=items][@checked]').val();
Get the text of the selected item
Copy code The code is as follows:
varitem= $("select[@name=items] option[@selected]").text();
select the item in the drop-down box The two elements are the currently selected values
Copy code The code is as follows:
$('#select_id')[0].selectedIndex=1 ;
The second element of the radio radio group is the currently selected value
Copy code The code is as follows:
$('input[@name=items]').get(1).checked=true;
Get value:
Text box, text area:
Copy code The code is as follows:
$("#txt").attr("value");
Multiple selection Box checkbox:
Copy code The code is as follows:
$("#checkbox_id").attr("value");
Single selection group radio:
Copy code The code is as follows:
$("input[@type=radio] [@checked]").val();
Drop-down box select:
Copy code The code is as follows:
$('#sel').val();
Control form elements:
Text box, text area:
Copy Code The code is as follows:
$("#txt").attr("value",'');//Clear the content
$("#txt").attr ("value",'11');//Fill content
Multiple selection box checkbox:
Copy code The code is as follows:
$("#chk1").attr("checked",'');//Unchecked
$("#chk2").attr("checked",true); //Tick
if($("#chk1").attr('checked')==undefined)//Judge whether it has been checked
Radio selection group radio:
Copy code The code is as follows:
$("input[@type=radio]").attr("checked",'2');//Set the item with value=2 as the currently selected item
Drop-down box select:
Copy code The code is as follows:
$("#sel").attr("value",'- sel3');//Set the item with value=-sel3 as the currently selected item
$("
The above is the detailed content of jquery operation select encyclopedia. For more information, please follow other related articles on the PHP Chinese website!