【问题标题】:SelectBoxIt only works on first instance of classSelectBoxIt 仅适用于类的第一个实例
【发布时间】:2017-12-31 09:22:41
【问题描述】:

我正在使用 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 时一切正常,但问题是在我打算使用它的其中一个页面上,滑块中有多个表单实例,因此我必须使用类。

【问题讨论】:

    标签: javascript jquery jquery-selectbox selectboxit


    【解决方案1】:

    我也试过用这个...

    $(".positioning").data("selectBox-selectBoxIt").selectOption(0);
    

    这将允许我定位多个类,但每个类都必须单独定位,但它只适用于每个类的第一个实例。

    最后我不得不使用每个表单具有的唯一 ID 附加元素类(取自用于创建滑块的 php while 循环),因此页面上的每个选择都有一个唯一的类(所以现在它没有如果我现在使用 id 而不是类也没关系)

    <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);
    

    不完全是我希望的解决方案,但它有效

    【讨论】:

      猜你喜欢
      • 2017-08-12
      • 1970-01-01
      • 2013-07-30
      • 1970-01-01
      • 1970-01-01
      • 2018-01-06
      • 1970-01-01
      • 1970-01-01
      • 2011-07-05
      相关资源
      最近更新 更多