![](/img/trans.png)
[英]How to trigger the native select box using SelectBoxIt jquery plugin
[英]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.