大家好,我使用 JQM 1.3 和 JQuery 1.9.1...我尝试让动态选择菜单在没有解决方案的情况下工作。
首先,我在 pagebeforeshow 事件中使用 createDocument(div...) 和 .setAttribute(id,...) 创建一个选择菜单。然后我在第一行、第二行和组合中使用了很多变体..
$("#select-keywords-list").selectmenu();
$("#select-keywords-list").selectmenu("refresh");
对我来说还没有任何效果..
添加后,我在 Domready($(#page).ready) 函数中监听它的更改事件。 在浏览器中它运行得很好,但在手机上我无法让它运行。希望有人能帮助我。
我还尝试了 native 菜单 true 和 false..
谢谢
马尔
最佳答案
工作示例:http://jsfiddle.net/Gajotres/dEXac/
$(document).on('pagebeforeshow', '#index', function(){
// Add a new select element
$('<select>').attr({'name':'select-choice-1','id':'select-choice-1','data-native-menu':'false'}).appendTo('[data-role="content"]');
$('<option>').html('Select option!').appendTo('#select-choice-1');
$('<option>').attr({'value':'1'}).html('Value 1').appendTo('#select-choice-1');
$('<option>').attr({'value':'2'}).html('Value 2').appendTo('#select-choice-1');
// Enhance new select element
$('select').selectmenu();
$(document).on('change', '#select-choice-1', function(){
alert($(this).find("option:selected").text());
});
});
还有一件事,不要使用 jQuery Mobile 准备好的文档,它们不能正常工作。而是使用 pageinit 事件。如果您想了解更多信息,请查看此处: jQuery Mobile: document ready vs page events
关于JQuery Mobile 1.3 选择菜单动态刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16298578/