我正在使用Fancybox在页面中间弹出一个div,其中有一个带有selectboxit插件样式的选择框:http://gregfranko.com/jquery.selectBoxIt.js/。现在,我将select值更改为默认值以外的内容,并关闭Fancybox。当我重新打开那个Fancybox时,select值仍然与我所选择的相同。我需要把它重置到默认状态。下面是我现在拥有的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/
发布于 2014-04-09 23:54:46
您可以使用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/
https://stackoverflow.com/questions/22966981
复制相似问题