Home > Web Front-end > JS Tutorial > jQuery's method of obtaining and assigning values ​​​​to html elements_jquery

jQuery's method of obtaining and assigning values ​​​​to html elements_jquery

WBOY
Release: 2016-05-16 17:13:35
Original
1026 people have browsed it

Jquery takes and assigns values ​​​​to basic controls TEXTBOX: var str = $('#txt').val(); $('#txt').val("Set Lbl Value"); //Text box , text area: $("#text_id").attr("value",'');//Clear content $("#text_id").attr("value",'test');//Fill content

TEXTBOX:

Copy code The code is as follows:

var str = $('# txt').val();
$('#txt').val("Set Lbl Value");

//Text box, text area:
$("#text_id").attr("value",'');//Clear the content
$("#text_id").attr(" value",'test');//Fill content

LABLE:

Copy code The code is as follows:

var str = $('# lbl').text();
$('#lbl').text("Set Lbl Value");

var valradio = $("input[@type=radio][@checked]").val();
var item = $('input[@name=items][@checked]'). val();
var checkboxval = $("#checkbox_id").attr("value");
var selectval = $('#select_id').val();
//Multiple selection Box checkbox:
$("#chk_id").attr("checked",'');//Make it unchecked
$("#chk_id").attr("checked",true) ;//Check
if($("#chk_id").attr('checked')==true) //Judge whether


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:
$("#select_id").attr("value" ,'test');//Set the item with value=test 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