繁体   English   中英

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

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

我正在使用Fancybox在页面中间弹出一个div,该div具有一个使用selectboxit jquery插件设置样式的选择框: http ://gregfranko.com/jquery.selectBoxIt.js/。 现在,将选择值更改为默认值以外的其他值,然后关闭Fancybox。 当我重新打开该Fancybox时,选择值仍与我选择的值相同。 我需要将其重置为默认值。 这是我现在拥有的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!');
            }
        });

“ afterClose”函数中的前两行不起作用。 第一个可能正在做某事,但刷新行在Firebug中表示:“ TypeError:$(...)。refresh不是函数$(selectBox).refresh();”。 有什么想法可以重设此选择框吗?

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

您可以使用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!');
         }
     });
 });

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

暂无
暂无

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

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