current position:Home>JQuery operation select (value, setting, selected)
JQuery operation select (value, setting, selected)
2021-08-22 05:30:24 【mb611f1a641bd18】
such as <select class="selector"></select>
1、 Set up value by pxx Check the item of
$(".selector").val("pxx");
2、 Set up text by pxx Check the item of
$(".selector").find("option[text='pxx']").attr("selected",true);
Here is a usage of brackets , The equal sign in square brackets is preceded by the attribute name , No quotes . A lot of times , The use of brackets can make logic very simple .
3、 Gets the... Of the currently selected item value
$(".selector").val();
4、 Gets the... Of the currently selected item text
$(".selector").find("option:selected").text();
The colon is used here , Mastering its usage will also make the code concise .
It is often used select Cascade of , That is, the second select With the first select Selected value changes . This is in jquery Is very simple .
Such as :$(".selector1").change(function(){
// First empty the second
$(".selector2").empty();
// In practical application , there option Generally, multiple are generated by loops
var option = $("<option>").val(1).text("pxx");
$(".selector2").append(option);
});
copyright notice
author[mb611f1a641bd18],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2021/08/20210822053018976P.html
The sidebar is recommended
- Crazy blessing! Tencent boss's "million JVM learning notes", real topic of Huawei Java interview 2020-2021
- JS JavaScript how to get the subscript of a value in the array
- How to implement injection in vuex source code?
- One line of code teaches you how to advertise on Tanabata Valentine's Day - Animation 3D photo album (music + text) HTML + CSS + JavaScript
- An article disassembles the pyramid architecture behind the gamefi outbreak
- BEM - a front-end CSS naming methodology
- Another ruthless character fell by 40000, which was "more beautiful" than Passat and maiteng, and didn't lose BMW
- Huang Lei basks in Zhang Yixing's album, and the relationship between teachers and apprentices is no less than that in the past. Netizens envy Huang Lei
- Zhou Shen sang the theme song of the film "summer friends and sunny days" in mainland China. Netizen: endless aftertaste
- August 23, 2021 Daily: less than three years after its establishment, Google dissolved the health department
guess what you like
-
The female doctor of Southeast University is no less beautiful than the female star. She has been married four times, and her personal experience has been controversial
-
There are many potential safety hazards in Chinese restaurant. The top of the program recording shed collapses, and the artist will fall down if he is careless
-
Introduction to flex flexible layout in CSS -- learning notes
-
CSS learning notes - Flex layout (Ruan Yifeng tutorial summary)
-
Today, let's talk about the arrow function of ES6
-
Some thoughts on small program development
-
Unwilling to cooperate with Wang Yibo again, Zhao Liying's fans went on a collective strike and made a public apology in less than a day
-
Zheng Shuang's 30th birthday is deserted. Chen Jia has been sending blessings for ten years. Is it really just forgetting to make friends?
-
Asynchronous solution async await
-
Analysis and expansion of Vue infinite scroll source code
Random recommended
- "The story of huiyeji" -- people are always greedy, and fairies should be spotless!
- Installing Vue devtool for chrome and Firefox
- Basic usage of JS object
- 1. JavaScript variable promotion mechanism
- Two easy-to-use animation JS that make the page move
- Front end Engineering - scaffold
- Java SQL Server intelligent fixed asset management, back end + front end + mobile end
- Mediator pattern of JavaScript Design Pattern
- Array de duplication problem solution - Nan recognition problem
- New choice for app development: building mobile applications using Vue native
- New gs8 Chengdu auto show announces interior Toyota technology blessing
- Vieira officially terminated his contract and left the team. The national security club sent blessings to him
- Less than 200000 to buy a Ford RV? 2.0T gasoline / diesel power, horizontal bed / longitudinal bed layout can be selected
- We are fearless in epidemic prevention and control -- pay tribute to the front-line workers of epidemic prevention!
- Front end, netty framework tutorial
- Xiaomi 11 | miui12.5 | android11 solves the problem that the httpcanary certificate cannot be installed
- The wireless charging of SAIC Roewe rx5 plus is so easy to use!
- Upload and preview pictures with JavaScript, and summarize the most complete mybatis core configuration file
- Ajax foundation - HTTP foundation of interview essential knowledge
- Cloud lesson | explain in detail how Huawei cloud exclusive load balancing charges
- [JS] 10. Closure application (loop processing)
- Left hand IRR, right hand NPV, master the password of getting rich