【问题标题】:How to remove elements from listview JQUERY mobile如何从listview JQUERY mobile中删除元素
【发布时间】:2012-01-04 12:59:05
【问题描述】:

有一个列表视图,它是在加载页面时动态加载的。 这会在列表视图中添加元素。 问题是我放置了后退按钮。在转到上一个屏幕并返回到当前屏幕后,它正在加载数据并附加到列表视图。

I need to remove the <li> elements from the list view.

The HTML code snippet.
<ul id="mymenu" data-role="listview" >
</ul>

Jquery Code Snippet.
$("#mypmenu").append('<li><a href='+ "#" + ' id="a"  "> <img src="letterheader.png" >'+ this.textContent + '  </a> </li>'); 


Now i need to remove the elements from the list view (mymenu)which are loaded already.

【问题讨论】:

    标签: jquery jquery-mobile


    【解决方案1】:

    先尝试清空列表,然后再添加列表项。之后,请确保调用 listview 小部件的刷新功能,以便 jQuery Mobile 正确呈现您的列表。

    $("#mypmenu").empty().append('<li><a href='+ "#" + ' id="a"  "> <img src="letterheader.png" >'+ this.textContent + '  </a> </li>').listview("refresh"); 
    

    另见http://forum.jquery.com/topic/dynamically-generated-listview

    【讨论】:

      【解决方案2】:

      $("mypmenu").empty(), followed by $("mypmenu").append()

      为我做这项工作

      【讨论】:

        【解决方案3】:

        这对我有用

        $("mypmenu li").remove();
        

        【讨论】:

          【解决方案4】:

          然后不要使用附加。
          使用

          $("#mypmenu").html('<li><a href='+ "#" + ' id="a"  "> <img src="letterheader.png" >'+ this.textContent + '  </a> </li>').listview("refresh");
          

          【讨论】:

            【解决方案5】:

            在“pagecreate”中编写您的代码,这只会运行一次代码。

            $(document).on("pagecreate", "#pageone", function () {}
            

            page create

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2018-01-17
              • 2015-10-13
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多