Home  >  Article  >  Web Front-end  >  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
WBOYOriginal
2016-05-16 17:13:351008browse

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
$("
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