我使用SelectBoxIt来样式化我的选择,如果我为它们使用ID,它可以很好地工作,但是如果我使用类,尽管它样式化它们都可以,但是大多数选项只会影响类的第一个元素。
我正在尝试获取它,以便当表单成功提交时,选择被重置,但只有第一个被重置。
我已经尝试使用jQuery来重置元素
$("input[name=positioning]").val($("input[name=positioning] option:first").val());
但所有这些操作都是重置隐藏在样式版本下的原始选择,因此现在显示的值不是所选的值。
我也试过..。
$(".exposure, .patient, .equip, .unit, .taken, .pathology, .pathway").selectBoxIt('selectOption', 0);
仅针对第一个元素
$(".exposure").selectBoxIt('selectOption', 0);
$(".patient").selectBoxIt('selectOption', 0);
同样,只针对第一个元素
$(".exposure, .patient, .equip, .unit, .taken, .pathology, .pathway").each(function(){
selectBoxIt('selectOption', 0);
});
出现错误selectBoxIt is not defined
时根本不起作用
使用ID时,一切工作正常,但问题是,在我打算使用它的其中一个页面上,滑块中将有多个表单实例,因此我必须使用类。
发布于 2017-07-25 21:30:39
我也试过用这个……
$(".positioning").data("selectBox-selectBoxIt").selectOption(0);
这将允许我针对多个类,但每个类都必须单独针对,但它只能在每个类的第一个实例上工作。
最后,我必须使用每个表单的唯一ID (取自用于创建滑块的php while循环)附加元素class,这样页面上的每个select都有一个唯一的类(所以现在我用id代替class也没有关系)
<form id="<?=$form_id?>">
<select class="positioning_<?=$form_id?>">
//rest of select here
</form>
var form_id = 'form_id'
$(".positioning_"+form_id).data("selectBox-selectBoxIt").selectOption(0);
不完全是我所希望的解决方案,但它是有效的
https://stackoverflow.com/questions/45303481
复制相似问题