How to clear the select boxes [closed]

旧巷老猫 提交于 2019-12-20 07:04:23

问题


I am hoping this will be a simple answer, I have used chosen drop downs for filtering the records. I have added another button for reseting the filter values.

I want to clear the chosen drop down on the "Reset" click.

I did try changing the selected values, but no luck.

Any pointers?


回答1:


Finally got answer to my question, it was asked in the GitHub for Choosen plugin.

Here is the code that works like charm:-

          $('.dropdownclass option:selected').removeAttr('selected');
          $('.dropdownclass').trigger('chosen:updated');

Hope this helps..




回答2:


your answer:

$(".category-filter").val("")

Should work if its got the class "category-filter", and attached in the button .click() function, and within the document.ready function. - Is the option value "" actually a select option that can be selected? as I believe it needs to be for this to work?

A fiddle to show..

http://jsfiddle.net/UmV6p/3/




回答3:


You would need to first reset it and then update chosen dynamically.

$(".category-filter").val(""); 

$(".category-filter").trigger("chosen:updated");     //version v1.0.0

$(".category-filter").trigger("chzn:updated");     //other than version v1.0.0

Hope this helps.



来源:https://stackoverflow.com/questions/21191111/how-to-clear-the-select-boxes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!