动态设置的jQuery UI Selectmenu值不会更改可见的选定值 [英] jQuery UI Selectmenu value set dynamically does not change visible selected value
问题描述
我正在使用jQuery UI Selectmenu,但无法设置所选渲染的值.似乎在基础选择中更改了选中的选项,但是选择菜单未显示更改.我正在呼叫.selectmenu('refresh',true),但是什么也没发生.
I am using jQuery UI Selectmenu and am having trouble setting the value of a rendered selected. It seems to change the selected option in the underlying select, but the selectmenu does not show the change. I am calling .selectmenu('refresh', true) but nothing happens.
这里是一个示例: http://jsfiddle.net/sociobit/wYBeL/
推荐答案
Hiya So 演示(解决方案) http://jsfiddle.net/wYBeL/43/而不是刷新,请尝试.selectmenu("value", selectedValue);
或(Hack) http://jsfiddle.net/wYBeL/36/(保持您的selectpopup设置:)哪种适合您
Hiya So demo (Solution) http://jsfiddle.net/wYBeL/43/ instead of refresh try .selectmenu("value", selectedValue);
OR (Hack) http://jsfiddle.net/wYBeL/36/ (keeps the selectpopup setting of yours :) What ever suits you
因此,我使用firebug检查了DOM,似乎selectmenu()样式:弹出窗口添加了额外的样式层,但#sel2值设置正确,您只需要使用正确的值设置正确的元素即可.我认为当您有一个Ajax填充页面的下拉菜单和刷新部分时,刷新将起作用.
So I checked the DOM using firebug and it seems the selectmenu() style: popup adds extra layer of styling but the #sel2 value is set correctly and you just need to setup the right element with correct value. I reckon refresh will work when you will have an ajax populating a dropdown and refreshing part of page.
嗯,您可以尝试查看API以获得更多详细信息,如果您不需要selectmenu弹出窗口,那么如果没有它,它也可以像@jiimw一样工作:(BUT样式变得很奇怪):
Hmm, you can try looking at API for more details and In case if you don't need selectmenu popup then without it this will work as well like @jiimw said: (BUt styling goes weird) : http://jsfiddle.net/wYBeL/35/ ;Please let me know if this doesn't help I will remove post.
额外链接: http://wiki.jqueryui.com/w/page/12138056 /Selectmenu
希望两者都有帮助.
此处查询代码
$(function() {
$('select').selectmenu({
style: 'popup'
});
$('#chksame').click(function() {
if ($(this).is(':checked')) {
var selectedValue = $('#sel1').val();
$('#sel2').val(selectedValue);
$('#sel2').selectmenu("value", selectedValue);
}
});
});
**或**
$(function() {
$('select').selectmenu({
style: 'popup'
});
$('#chksame').click(function() {
if ($(this).is(':checked')) {
var selectedValue = $('#sel1').val();
$('#sel2').val(selectedValue);
// set the right element with the select value
$('#sel2-button span').text($("#sel2 option[value='" + selectedValue +"']").text());
$('#sel2').selectmenu('refresh', true);
}
});
});
欢呼
这篇关于动态设置的jQuery UI Selectmenu值不会更改可见的选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!