【问题标题】:Selectboxit - How to refresh selected values in selectboxitSelectboxit - 如何刷新 selectboxit 中的选定值
【发布时间】:2014-05-19 06:50:53
【问题描述】:

我正在使用 selectboxit 插件 - http://gregfranko.com/jquery.selectBoxIt.js/

对于普通的 select 元素,设置 selected 元素的 prop 将更新 UI。使用 selectboxit 无法正常工作。

演示 - http://jsfiddle.net/uXM6Y/

var selectBox = $("select#test").selectBoxIt().data("selectBoxIt");

$('.btn').click(function(e){
    $('#test option:contains("Great")').prop('selected', true);
});

当我单击演示中的更新按钮时,选择未设置为更新的值。如果我删除 selectboxit 插件,它工作正常。

【问题讨论】:

    标签: javascript jquery jquery-plugins jquery-selectbox


    【解决方案1】:

    您想使用您的插件版本中不存在的 selectboxit 方法 API。

    从这里获取它(确保为您的下载选择了 setOption 方法): http://gregfranko.com/jquery.selectBoxIt.js/customDownload.html#javascript-downloads

    并按如下方式更改您的 javascript:

    var selectBox = $("select#test").selectBoxIt().data("selectBoxIt");
    
    $('.btn').click(function(){
        selectBox.selectOption('Great');
    });
    

    编辑:这是使用完整 selectboxit 插件的小提琴的更新版本: http://jsfiddle.net/uXM6Y/2/

    【讨论】:

    • 请制作小提琴以获得更好的插图。
    • 按预期工作。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-30
    • 1970-01-01
    • 2019-12-24
    • 1970-01-01
    • 1970-01-01
    • 2017-09-18
    • 1970-01-01
    相关资源
    最近更新 更多