简体   繁体   English

如何使用selectboxit使用jQuery重置选择框

[英]How to reset select box with jquery using selectboxit

I am using Fancybox to pop up a div in the middle of the page that has a select box styled with the selectboxit jquery plugin here: http://gregfranko.com/jquery.selectBoxIt.js/ . 我正在使用Fancybox在页面中间弹出一个div,该div具有一个使用selectboxit jquery插件设置样式的选择框: http ://gregfranko.com/jquery.selectBoxIt.js/。 Now I change the select value to something other than the default and close the Fancybox. 现在,将选择值更改为默认值以外的其他值,然后关闭Fancybox。 When I reopen that Fancybox, the select value is still the same as what I had selected. 当我重新打开该Fancybox时,选择值仍与我选择的值相同。 I need it to reset to the default. 我需要将其重置为默认值。 Here is the javascript coode that I have right now: 这是我现在拥有的JavaScript代码:

var selectBox = $("select").selectBoxIt();
        $(".fancybox, #cartLink").fancybox({
            width: 800,
            autoHeight: true,
            minHeight: 385,
            scrolling: 'no',
            autoSize: false,
            afterClose: function () {
                $(selectBox).val('0');
                $(selectBox).refresh();
                console.log('should be reset!');
            }
        });

The first two lines in the 'afterClose' function do not work. “ afterClose”函数中的前两行不起作用。 The first might be doing something but the refresh line says this in Firebug: "TypeError: $(...).refresh is not a function $(selectBox).refresh();" 第一个可能正在做某事,但刷新行在Firebug中表示:“ TypeError:$(...)。refresh不是函数$(selectBox).refresh();”。 Any ideas how I can reset this selectbox? 有什么想法可以重设此选择框吗?

Edit: As requested, here is a fiddle: http://jsfiddle.net/Qh2NP/1/ 编辑:根据要求,这是一个小提琴: http : //jsfiddle.net/Qh2NP/1/

You can use the SelectBoxIt selectOption() method. 您可以使用SelectBoxIt selectOption()方法。 Like this: 像这样:

 $(document).ready(function () {
     var selectBox = $("select").selectBoxIt();
     $("#cartLink").fancybox({
         width: 800,
         autoHeight: true,
         minHeight: 385,
         scrolling: 'no',
         autoSize: false,
         afterClose: function () {
             $(selectBox).selectBoxIt('selectOption', 0);
             $(".notification").hide();
             console.log('should be reset!');
         }
     });
 });

Here is a link to your updated jsfiddle: http://jsfiddle.net/Qh2NP/2/ 这是更新的jsfiddle的链接: http : //jsfiddle.net/Qh2NP/2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM