Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the drop-down selection of different display by jquery

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces jquery how to achieve the drop-down selection of different display of different related knowledge, the content is detailed and easy to understand, the operation is simple and fast, with a certain reference value, I believe that after reading this jquery how to achieve the drop-down choice of different articles will have a harvest, let's take a look at it.

The following steps describe how to get data from a database and display it dynamically at the front end.

Step 1: static select of jsp page:

Select A

Select B

Select C

Note:

1. There is no problem with using static select in some scenarios. However, when the product needs are different, dynamic select is more suitable for its diversity.

2. Select can be written in many ways, and this is the easiest one.

Step 2: jQuery acquires dynamic data through ajax request and displays it on the jsp page.

Function IninDepart () {

$("# selectSM") Remove (); / / clear the select list data

Var state=1

$.ajax ({

Type: "POST"

Url: "/ getItemDepartList.do"

DataType: "JSON"

Data: {}

Success: function (msg)

{

$("# selectSM") Prepend ("Please select"); / / add the first option value

For (var item0; I

< msg.rows.length; i++) {   //如果在select中传递其他参数,可以在option 的value属性中添加参数   //$("#selectSM")。append(""+msg.rows[i]+"");   $("#selectSM")。append(""+msg.rows[i]+"");   }   },error:function(){   alertLayer("获取数据失败","error");   }   });   }   注意:这里使用的是jQuery、ajax,其他方式也可以实现。   步骤三:后台数据的处理。   public JSONObject getItemDepartList(HttpServletRequest request) throws Exception{   //查询select数据   List>

List=appServices.getAppList ()

System.out.println ("list:" + list)

/ / get the data and store it in the array

String [] depart=null

For (Map map: list) {

For (String k: map.keySet ()) {

Depart= ((String) map.get (k)). Split (,)

System.out.println ("depart:" + depart)

}

}

/ / remove duplicate data from the array and store it in list

List strList=new ArrayList ()

For (int item0; I

If (! StrList.contains (de part [I])) {

StrList.add (de part [I])

}

}

System.out.println ("strList:" + strList)

JsonObject.put ("rows", strList)

Return jsonObject

}

Note: due to the problem of returning data in the background, it is necessary to intercept the data and remove the duplicate data. If you don't have this requirement, you can return an array or list directly to the front end.

This is the end of the article on "how to realize the drop-down selection of jquery to display differently". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to achieve jquery drop-down options different display different". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report