Home >Web Front-end >Bootstrap Tutorial >How to clear the selected state of bootstrap-select drop-down box?

How to clear the selected state of bootstrap-select drop-down box?

青灯夜游
青灯夜游forward
2020-12-07 17:47:424731browse

How to clear the selected state of bootstrap-select drop-down box?

Recommended related tutorials: "bootstrap Video Tutorial"

In PC-side projects, a large number of data list pages often appear, involving drop-down boxes Select filter conditions;

When using the bootstrap-select drop-down box, how can I click the reset button to clear the selected state of the drop-down box and restore it to the default state?

As shown in [Picture 1]

How to clear the selected state of bootstrap-select drop-down box?

When we choose to touch a condition

As shown in [Picture 2]

How to clear the selected state of bootstrap-select drop-down box?

At this time, click the reset button to return the state of [Figure 2] to [Figure 1]. We will use many methods, such as:

            $("#loc_province_search").attr("lang",'0');//将下拉列表属性lang置为初始值  
            $("#loc_city_search").attr("lang",'0');//将下拉列表属性lang置为初始值  
            $("#loc_town_search").attr("lang",'0');//将下拉列表属性lang置为初始值  
            $(".txt_classification").attr("lang",'0');//将下拉列表属性lang置为初始值  
            $(".txt_industry").attr("lang",'0');//将下拉列表属性lang置为初始值  
            $(".txt_segmentation").attr("lang",'0');//将下拉列表属性lang置为初始值  
            $(".customer_busi_status2").attr("lang",'0');//将下拉列表属性lang置为初始值  
            $("#searchkey").attr("lang",&#39;0&#39;);//将下拉列表属性lang置为初始值</span>

or this:

document.getElementById("selectid").options.length = 0;

But we have found many methods that will not work for the bootstrap-select drop-down box. In fact, it is because bootstrap-select needs to refresh the current drop-down box on a clear basis and reload it

The code is as follows:

    document.getElementById("searchPayState").options.selectedIndex = 0; //回到初始状态
    $("#searchPayState").selectpicker(&#39;refresh&#39;);//对searchPayState这个下拉框进行重置刷新

The above code can solve the problem

For more programming-related knowledge, please visit: Programming Learning! !

The above is the detailed content of How to clear the selected state of bootstrap-select drop-down box?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete