Home > Web Front-end > JS Tutorial > jquery gets the value in the form element sample code_jquery

jquery gets the value in the form element sample code_jquery

WBOY
Release: 2016-05-16 17:27:52
Original
936 people have browsed it

jquery notes:

Copy code The code is as follows:

$("input[name='radio_name ']:checked”).val()
1
2
3

The things on the Internet are too messy , and different versions of jQuery may be written differently. After searching and doing experiments, what is written below is the
jquery radio value, checkbox value, select value, radio selected, checkbox selected, under jQuery 1.3.2 version. select, and its related settings:
Get the value of a set of radio selected items: var item = $('input[name=items][checked]').val();

Get selectThe text of the selected item
var item = $("select[@name=items] option[@selected]").text();
Get the text of the selected item: var item = $( "select[name=items] option[selected]").text(); or
$("select[name=items]").find("option:selected").text();
The second element of the select drop-down box is the currently selected value: $('#select_id')[0].selectedIndex = 1;
The element of the select drop-down box value = 'val' is the currently selected item: $("select [name=items] option[value='val']").attr("selected","selected");
The second element of the radio radio selection group is the currently selected item: $('input[@ name=items]').get(1).checked = true; or $('input[name=items]').attr("checked",1′);
radio value = 'val' The element is the currently selected item: $('input[name=items][value='val']').attr("checked","checked");
Get the value:
Text box, text area :$("#txt").attr("value");
Multiple selection box checkbox: $("input[name='checkbox':checked]").each(function(){
var val = $(this).val();
});
Radio selection group radio: $("input[type=radio][checked]").val();
Drop-down box select value: $('select').val();
Text value selected by drop-down box select: $("select").find("option:selected").text();

Control form elements:
Text box, text area: $("#txt").attr("value","); //Clear content
$("#txt").attr(" value”,’11′); //Fill content
Multiple selection box checkbox: The second element of
checkbox is checked: $("input[name=items]").get(1). checked = true; //Check
$("input[name=items]").get(1).checked = false; //Uncheck
before the element with value='val' in checkbox Tick: $("input[name=item][value='val']").attr("checked",true); or $("input[name=item][value='val']") .attr("checked","checked");
if($("input[name=item][value='val']").attr('checked')==true) //Determine whether Already 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: $(”#sel”).attr(”value”,'-sel3′);//Set the item with value=-sel3 as the currently selected item
$(”
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template