Home > Web Front-end > JS Tutorial > body text

Summary of various methods of jQuery manipulating input values_jquery

WBOY
Release: 2016-05-16 17:13:21
Original
1267 people have browsed it

Get the selected value
Get the value of a group of radio selected items

Copy code The code is as follows:

var item = $('input[@name=items][@checked]').val();

Get the text of the selected item
Copy code The code is as follows:

var item = $("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 of the radio radio selection group 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");

$("#txt").val();


Multiple selection box checkbox:
Copy code The code is as follows:

$("#checkbox_id").attr("value");

Radio 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",'');//Do not type Check
$("#chk2").attr("checked",true);//Tick
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
$("1111 2222").appendTo("#sel")//Add the option of the drop-down box
$("#sel").empty();//Clear the drop-down box

=======================

In Jquery, use $("#id") to get the input element of the page, which is equivalent to document.getElementById("element"). However, what you get is a Jquery object, not a dom element object. Value is an attribute of the dom element object. Therefore, the value cannot be obtained using $("#id").value. The method of obtaining the value is as follows: Value: val = $("#id")[0].value; $( "#id")[0].value = "new value"; Assignment: $("#id")[0].value = "new value";
or $("#id").val( "new value"); val = $("#id").attr("value");

================================== 

jquery input text radio check select

Copy code The code is as follows:





Untitled Document


dd

ff
55

jgdg
jgdg






fgfooHello



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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!