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

dmi*_*er1 2 jquery jquery-plugins

我正在使用Fancybox在页面中间弹出一个div,它有一个用selectboxit jquery插件设置样式的选择框:http://gregfranko.com/jquery.selectBoxIt.js/ .现在我将选择值更改为默认值以外的其他值并关闭Fancybox.当我重新打开Fancybox时,选择值仍然与我选择的相同.我需要它重置为默认值.这是我现在的javascript coode:

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!');
            }
        });
Run Code Online (Sandbox Code Playgroud)

'afterClose'函数中的前两行不起作用.第一个可能是做某事,但刷新线在Firebug中说:"TypeError:$(...).refresh不是函数$(selectBox).refresh();" 我有什么想法可以重置这个选择框?

编辑:根据要求,这是一个小提琴:http://jsfiddle.net/Qh2NP/1/

Gre*_*nko 5

您可以使用SelectBoxIt selectOption()方法.像这样:

 $(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!');
         }
     });
 });
Run Code Online (Sandbox Code Playgroud)

这是您更新的jsfiddle的链接:http://jsfiddle.net/Qh2NP/2/