简体   繁体   English

如何在jquery mobile中替换li?

[英]How to replace li in jquery mobile?

    var $areas = $('#ulArs'); //To take the control of ulArs
    $areas.empty();
    $areas.append('<li id="li1" data-role="list-divider"></li>');
    for (var i = 0; i < result.rows.length; i++) 
    {
     li = "<li id='home_nav' style='white-space:normal'></li>";
    }
     $areas.append(li).trigger('create');
     $areas.listview('refresh');

I m creating dynamic UL with multiple li.i want to replace one particular li on change of checkbox without refreshing.can it be possible in jquery mobile? 我正在创建具有多个li.i的动态UL。想要在更改复选框时替换一个特定的li而不刷新。可以在jquery mobile中使用它吗?

As fas as I know , you definitely should call refresh method. 就像我所知道的那样,你绝对应该调用刷新方法。 But what is a problem? 但问题是什么? According to this information('Updating lists' section) : "Note that the refresh() method only affects new nodes appended to a list. This is done for performance reasons. Any list items already enhanced will be ignored by the refresh process." 根据此信息(“更新列表”部分) :“请注意,refresh()方法仅影响附加到列表的新节点。这是出于性能原因而完成的。刷新过程将忽略任何已增强的列表项。”

var $areas = $('#ulArs'); //To take the control of ulArs
$areas.empty();
$areas.append('<li id="li1" data-role="list-divider"></li>');
var li = '';
for (var i = 0; i < result.rows.length; i++) {
  li += '<li class="home_nav" id="home_nav-' + i + '" style="white-space:normal"></li>';
}
$areas.append(li).trigger('create');
$areas.listview('refresh');

you can refer to a li with id , for example: 你可以参考带有idli ,例如:

$('#home_nav-0')

or adding any other information the element li , for example data 或添加元素li任何其他信息,例如data

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

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