Home >Web Front-end >JS Tutorial >jquery operation select encyclopedia_jquery

jquery operation select encyclopedia_jquery

WBOY
WBOYOriginal
2016-05-16 16:51:201332browse

Add option

Copy code The code is as follows:

$('#id') .append("");//Append an option
$('#id').prepend(""); //Insert an option for select


Remove option
Copy code The code is as follows:

$("#ID option").each(function(){
if($(this).val()= =111){
$(this).remove();
}
});

$("

2, radio button:

Copy code The code is as follows:

$("input[@type=radio][@ checked]").val();//Get the value of the selected item of the radio button (note that there is no space in the middle)
$("input[@type=radio][@value=2]").attr( "checked",'checked');//Set the radio button value=2 to 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 in the checkbox
$("input[@type=checkbox][@checked]").each(function( ){//Since multiple check boxes are generally selected, you can output in a loop
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 methods.

Copy code The code is as follows:




aaass



jquery radio value, checkbox value, select value, radio selected, checkbox selected, select selected, and related to obtain 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();

The second element of the select drop-down box is the currently selected value

Copy code The code is as follows:

$('#select_id')[0].selectedIndex=1;

The second element of the radio radio selection 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");

Radio 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);// Checked
if($( "#chk1").attr('checked')==undefined)//Determine whether it has been checked

Radio group radio:
$("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
$("1111 2222").appendTo("#sel")//Add the option
$("#sel").empty() of the drop-down box; // 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();

The second element of the select drop-down box is the currently selected value

Copy code The code is as follows:

$('#select_id')[0].selectedIndex=1;

The second element of the radio radio selection 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");

Radio 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);// Checked
if($( "#chk1").attr('checked')==undefined)//Determine whether it has been checked

Radio 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
$("< ;option value='2'>2222").appendTo("#sel")//Add the option
$("#sel").empty() of the drop-down box;//Clear the drop-down box Box
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn