简体   繁体   English

Selectboxit - 如何刷新selectboxit中的选定值

[英]Selectboxit - How to refresh selected values in selectboxit

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

With a normal select element, setting the prop of selected element will update the UI. 使用普通的select元素,设置所选元素的prop将更新UI。 With selectboxit it is not working. 使用selectboxit它无法正常工作。

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

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

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

When i click on the update button in the demo, select is not set to the updated value. 当我单击演示中的更新按钮时,选择未设置为更新的值。 If i remove the selectboxit plugin it works fine. 如果我删除selectboxit插件,它工作正常。

You want to use the selectboxit method API, which is not present in your version of the plugin. 您想使用selectboxit方法API,该API在您的插件版本中不存在。

Get it from here (make sure that the setOption method is selected for your download): http://gregfranko.com/jquery.selectBoxIt.js/customDownload.html#javascript-downloads 从这里获取它(确保选择了setOption方法供您下载): http//gregfranko.com/jquery.selectBoxIt.js/customDownload.html#javascript-downloads

And change your javascript as follows: 并按如下方式更改您的JavaScript:

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

$('.btn').click(function(){
    selectBox.selectOption('Great');
});

EDIT: Here is an updated version of your fiddle using the complete selectboxit plugin: http://jsfiddle.net/uXM6Y/2/ 编辑:这是使用完整的selectboxit插件的小提琴的更新版本: http//jsfiddle.net/uXM6Y/2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM