How to modify the selected value of select in jquery

青灯夜游
Release: 2022-09-07 17:57:28
Original
5627 people have browsed it

Modification steps: 1. Use the attribute selector to select the original selected value, and use the attr() function to remove the selected state, the syntax is "$("[selected]").attr("selected", false) ;"; 2. Obtain the specified option element through the id attribute value, and use the attr() function to set the selected state of the element. The syntax is "$("#id value").attr("selected", "selected");" .

How to modify the selected value of select in jquery

The operating environment of this tutorial: windows7 system, jquery3.6.1 version, Dell G3 computer. The

select element creates a single-select or multiple-select menu. The

option element defines an option (an entry) in a drop-down list.

The browser displays the content in the

How to modify the select value in jquery

In jquery, you can modify the select value by adding the selected attribute to the specified option element.

Attribute Value Description
selected selected Specifies that the option appears selected (when first displayed in the list).

Implementation steps:

Step 1. Use the attribute selector to select the original selected value and use attr() The function removes the selected state

$("[selected]").attr("selected", false);
Copy after login

Step 2. Obtain the specified option element through the id attribute value, and use the attr() function to set the selected state for the element

$("#id值").attr("selected", "selected");
Copy after login

Implementation example code



	
		
		
		
	
	
		
		
	
Copy after login

How to modify the selected value of select in jquery

##Description:

The attr() method can set the attributes and values ​​of the selected element.

Syntax for setting a single property

$(selector).attr(attribute,value)
Copy after login

ParametersDescriptionSpecifies the name of the attribute. Specifies the value of the attribute.
attribute
value

Set multiple attribute/value pairs

Set more than one attribute and value for the selected element.

$(selector).attr({attribute:value, attribute:value ...})
Copy after login
ParameterDescriptionSpecify one or more attribute/value pairs.
attribute:value
[Recommended learning:

jQuery video tutorial, web front-end video

The above is the detailed content of How to modify the selected value of select in jquery. For more information, please follow other related articles on the PHP Chinese website!

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