


JQuery gets the text content of multiple select tag options (example)
The following editor will bring you an articleJQuery Get the text content (example) of multiple select tag options. The editor thinks it's pretty good, so now I'll share the jquery source code with you and give it as a reference. If you are interested in jquery, follow the editor to have a look.
According to the id attribute of option, modify the text value
$("#sel_p .select_class option[id='-选择省-']").text(data.province).attr("selected",true); $("#sel_p .select_class option[id='-选择市-']").text( data.city).attr("selected",true); $("#sel_p .select_class option[id='-选择区-']").text( data.area).attr("selected",true); $("#sel_p .select_class option[id='-选择街-']").text( data.street).attr("selected",true);
Get multiple selects (use class The text values of all options under the attribute (the same value)
$("#sel_p .select_class option").each(function(){ //遍历所有option标签 var text = $(this).text(); //获取option的text alert(text);//显示的是当前这个option的text值 if(txt == "选择省") $("#sel_p .select_class option[id='-选择省-']").text(data.province).attr("selected",true); if(txt == "选择市") $("#sel_p .select_class option[id='-选择市-']").text( data.city).attr("selected",true); if(txt == "选择区") $("#sel_p .select_class option[id='-选择区-']").text( data.area).attr("selected",true); if(txt == "选择街") $("#sel_p .select_class option[id='-选择街-']").text( data.street).attr("selected",true); });
If there is no cascading relationship in the select, then all options have been loaded and can be displayed using the following methodQuery The data
$("#sel_p .select_class option[id="+data.province+"]").attr("selected",true); $("#sel_p .select_class option[id="+data.city+"]").attr("selected",true); $("#sel_p .select_class option[id="+data.area+"]").attr("selected",true); $("#sel_p .select_class option[id="+data.street+"]").attr("selected",true);
Another way to get all options is equivalent to spelling all text into string and storing each character in the map
var map = $("#sel_p .select_class option").map(function(){ alert($(this).text());//显示单个option的text text1 return $(this).text(); }).get().join(","); alert(map);//显示的是 text1,text2,text3 alert(map[0]);//显示 t
Improve on the basis of the above, use array array to store the queried data, and use for loop to operate the data
var array = new Array(); $("#leaf .form-control option").map(function(){ array.push($(this).text()); }) for(var i = 0; i < array.length; i ++ ){ alert(array[i]);//显示每个option的text text1,text2,text3 }
The above article JQuery gets the text content (example) of multiple select tag options. This is all the content that the editor has shared with you. I hope it can give you a reference! !
Related recommendations:
Summary of DOM node operation methods in jQuery
bootstrap editable drop-down box jquery.editable-select Detailed example explanation
js, jQuery and easyui realize the designated assignment of the drop-down box example sharing
The above is the detailed content of JQuery gets the text content of multiple select tag options (example). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

When browsing Douyin works, we often see a clock icon behind the tag. So, what exactly is this clock? This article will focus on the discussion of "What is the clock behind the Douyin label", hoping to provide some useful reference for your use of Douyin. 1. What is the clock behind the Douyin label? Douyin will launch some hot topic challenges. When users participate, they will see a clock icon after the tag, which means that the work is participating in the topic challenge and displays the remaining time of the challenge. For some time-sensitive content, such as holidays, special events, etc., Douyin will attach a clock icon after the label to remind users of the validity period of the content. 3. Popular tags: When a tag becomes popular, Douyin will add a clock icon after the tag to indicate that the tag is

As a popular short video social platform, Douyin has a huge user base. For Douyin creators, using tags to attract traffic is an effective way to increase the exposure of content and attract attention. So, how does Douyin use tags to attract traffic? This article will answer this question in detail for you and introduce related techniques. 1. How to add tags on Douyin to attract traffic? When posting a video, make sure to choose tags that are relevant to the content. These tags should cover the topic and keywords of your video to make it easier for users to find your video through tags. Leveraging popular hashtags is an effective way to increase your video’s exposure. Research current popular tags and trends and incorporate them into your video descriptions and tags. These popular tags usually have higher visibility and can attract the attention of more viewers. 3. Label

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s
