RadioButton, input, CheckBox value assignment implementation code in jQuery

PHP中文网
Release: 2023-02-28 18:18:01
Original
1664 people have browsed it

1. jquery gets the radio group radio

$("input[name='name']:checked").val();
Copy after login

2. jquery gets the next value of radiobutton

$("input[name='name']:checked").next().text()$("input[name='name']:checked").val()
Copy after login

3. jquery gets the input value

$('#id').val()
Copy after login

4. jquery determines the checkbox

$("#id:checkbox").attr("checked")
取值 $("#id").attr("value");
Copy after login

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();
Copy after login

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();
Copy after login

Get the value selected by select:

$("#ddlRegType ").val();
Copy after login

Get the index selected by select:

$("#ddlRegType ").get(0).selectedIndex;
Copy after login

Set select:
Set select selected index:

$("#ddlRegType ").get(0).selectedIndex=index;//index为索引值
Copy after login

Set select selected value:

$("#ddlRegType ").attr("value","Normal“);
$("#ddlRegType ").val("Normal");
$("#ddlRegType ").get(0).value = value;
Copy after login

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=&#39;jQuery&#39;]").attr("selected", true);
Copy after login

Set select option item:

$("#select_id").append("
Copy after login

Clear Select:

$("#ddlRegType ").empty();
Copy after login
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!