【问题标题】:Manually triggering the styling on a jQuery mobile select list手动触发 jQuery 移动选择列表上的样式
【发布时间】:2012-02-11 21:15:20
【问题描述】:

我正在构建一个带有 Ajax 调用的选择列表,该调用在另一个选择列表更改时触发。

页面使用 jQuery 样式正确加载,但是当我用新的 div 替换我的 ajax 容器时,我无法让 jQuery mobile 对其进行格式化。这意味着它会恢复为原生选择列表格式。

我已经尝试了JQM documentation 中的建议:

var myselect = $("select#foo");
myselect[0].selectedIndex = 3;
myselect.selectmenu("refresh");

但这不起作用。我的页面最初加载如下:

<div id="ajax-destination">
     <select id="destinationAirport" data-native-menu="false">
      <option value="-- Please Select --" data-placeholder="true">-- Please Select --</option>
     </select>

这是我的 jQuery 代码,包裹在另一个选择列表的更改函数中。

$('#ajax-destination').empty();
$.post(url, { departureAirport : departureAirport }, function(data) {
    $('#ajax-destination').append(data);
var myselect = $("#destinationAirport");
myselect[0].selectedIndex = 1;
myselect.selectmenu("refresh");
});

我能想到的唯一另一种方法是通过 Ajax 返回一个 JSON 数组并使用它来将选项添加到选择列表中,但我更愿意只发送格式化的 HTML,因为它更易于遵循。

【问题讨论】:

  • 你可以试试 myselect.trigger('create');
  • 嗨菲尔,你能回答我吗?完整的解决方案是: $.post(url, { leaveAirport : leaveAirport }, function(data) { $('#ajax-destination').append(data).trigger( "create" ); });跨度>

标签: jquery-mobile


【解决方案1】:

如果 myselect.selectmenu("refresh");myselect.selectmenu("refresh",true); 不起作用,您可以随时使用刷新页面

you could try myselect.trigger('create');

【讨论】:

    【解决方案2】:

    @安迪:

    myselect.selectmenu("刷新");将刷新选择框和 where as myselect.selectmenu('refresh', true);将重建选择菜单。它可能会帮助你。检查此链接一次http://forum.jquery.com/topic/how-to-add-items-and-refresh-the-select-menu-in-jquery-mobile

    【讨论】:

      猜你喜欢
      • 2011-07-13
      • 2011-06-17
      • 2011-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-23
      • 2012-11-21
      • 1970-01-01
      相关资源
      最近更新 更多