JQuery Hide Option doesn't work in IE and Safari

后端 未结 7 1982
天命终不由人
天命终不由人 2020-11-30 09:58

I\'m trying to hide a few options in a dropdown box using .hide(). This works perfectly fine in firefox and chrome, but it doesn\'t work in IE and Safari. My original code i

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 10:41

    I tried the solution that uses around options, but found that it didn't work for me in all browsers.

    I've made a jQuery Plugin that solves this very nicely. With it, you would do this:

    $('#selection1').hideOption('1');
    $('#selection1').showOption('1');
    

    You can hide and show them as much as you want, and they will keep their original order and any .data('x') values you've assigned to the option. It works in all browsers. You can see that in this sample: jsFiddle - Toggle Dropdown Options

    You can get the Toggle Dropdown Options plug-in. If you don't like plug-ins, just copy the JavaScript code from it to your own project's JavaScript file. See the Read the Docs link on the plug-in for more information!

提交回复
热议问题