Home > Article > Backend Development > RadioButton, input, CheckBox value assignment implementation code in jQuery
1. jquery gets the radio group radio
$("input[name='name']:checked").val();
2. jquery gets the next value of radiobutton
$("input[name='name']:checked").next().text()$("input[name='name']:checked").val()
3. jquery gets the input value
$('#id').val()
4. jquery determines the checkbox
$("#id:checkbox").attr("checked") 取值 $("#id").attr("value");
Assignment is to give the value directly in text(), val()
How does JQUERY get the text, areatext, radio, checkbox, and select values?
$("input").val(); $("textarea").text(); $("select").val();
Control form elements:
Text box, text area: $("#txt").attr("value",'');//Clear content
$("#txt").attr("value",'11');//Fill content
Multiple selection box checkbox: $("#chk1").attr("checked",'' );//Unchecked
$("#chk2").attr("checked",true);//Checked
if($("#chk1").attr('checked') ==undefined) //Judge whether
radio group radio has been checked: $("input[@type=radio]").attr("checked",'2');//Set value The item =2 is the currently selected item
drop-down box select: $("#sel").attr("value",'-sel3');//Set the item value=-sel3 as the currently selected item Item
$("
jQuery Gets and sets the value of the select drop-down box Article Category:.net Programming
Get Select:
Get select selected text:
$("#ddlRegType").find("option:selected").text();
Get the value selected by select:
$("#ddlRegType ").val();
Get the index selected by select:
$("#ddlRegType ").get(0).selectedIndex;
Set select:
Set select selected index:
$("#ddlRegType ").get(0).selectedIndex=index;//index为索引值
Set select selected value:
$("#ddlRegType ").attr("value","Normal“); $("#ddlRegType ").val("Normal"); $("#ddlRegType ").get(0).value = value;
Set select selected text:
var count=$("#ddlRegType option").length; for(var i=0;i<count;i++) { if($("#ddlRegType ").get(0).options[i].text == text) { $("#ddlRegType ").get(0).options[i].selected = true; break; } } $("#select_id option[text='jQuery']").attr("selected", true);
Set select option item:
$("#select_id").append("
Clear Select:
$("#ddlRegType ").empty();