Home Backend Development PHP Tutorial RadioButton, input, CheckBox value assignment implementation code in jQuery

RadioButton, input, CheckBox value assignment implementation code in jQuery

Jun 06, 2017 pm 04:15 PM
jquery value Assignment

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

Set select option item:

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

Clear Select:

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of jQuery reference methods: Quick start guide Detailed explanation of jQuery reference methods: Quick start guide Feb 27, 2024 pm 06:45 PM

Detailed explanation of jQuery reference methods: Quick start guide

How to use PUT request method in jQuery? How to use PUT request method in jQuery? Feb 28, 2024 pm 03:12 PM

How to use PUT request method in jQuery?

Disable or enable automatic copy selection for copying in Terminal Disable or enable automatic copy selection for copying in Terminal Mar 24, 2024 am 09:46 AM

Disable or enable automatic copy selection for copying in Terminal

How to remove the height attribute of an element with jQuery? How to remove the height attribute of an element with jQuery? Feb 28, 2024 am 08:39 AM

How to remove the height attribute of an element with jQuery?

jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

jQuery Tips: Quickly modify the text of all a tags on the page

Use jQuery to modify the text content of all a tags Use jQuery to modify the text content of all a tags Feb 28, 2024 pm 05:42 PM

Use jQuery to modify the text content of all a tags

Understand the role and application scenarios of eq in jQuery Understand the role and application scenarios of eq in jQuery Feb 28, 2024 pm 01:15 PM

Understand the role and application scenarios of eq in jQuery

Summary of commonly used file operation functions in PHP Summary of commonly used file operation functions in PHP Apr 03, 2024 pm 02:52 PM

Summary of commonly used file operation functions in PHP

See all articles