0

当我打开主页(在此URL中)时,它在列表中有 4 个项目,然后我单击另一个链接(在页脚中我单击联系人)和在联系页面中,当我再次单击主页时(在页脚位置链接)它再次附加项目如何我可以清除以前的项目吗?

这是我的主页代码

$(document).ready(function (e) {

                $.getJSON('http://xx1', function (data) {

                    $.each(data.markers, function (i, marker) {

                        if (marker.PlaceExtra3 === '1') {

                            $("#listeu").append("<li data-role='list-divider' role='heading' class='ui-li ui-li-divider ui-bar-b ui-li-has-count' style='text-align:center'> <a href='http://localhost:65028/Home/KonuDetail/ " + marker.PlaceID + "' </a> " + marker.PlaceExtra2 + " - " + marker.PlaceName + " </li>");
                            $("#listeu li:last").fadeIn("slow");
                            $(".ui-btn-inner:eq(0)").css("background", 'red');
....
4

1 回答 1

0

Use .empty() to clear your list.

$.getJSON('http://xx1', function (data) {
    // empty list before the loop to clear the list
    $("#listeu").empty();
    // list is now empty, continue as normal
    $.each(data.markers, function (i, marker) {
    if (marker.PlaceExtra3 === '1') {
        $("#listeu").append("<li data-role='list-divider' role='heading' class='ui-li ui-li-divider ui-bar-b ui-li-has-count' style='text-align:center'> <a href='http://localhost:65028/Home/KonuDetail/ " + marker.PlaceID + "' </a> " + marker.PlaceExtra2 + " - " + marker.PlaceName + " </li>");
        $("#listeu li:last").fadeIn("slow");
        $(".ui-btn-inner:eq(0)").css("background", 'red');
于 2013-04-16T21:06:32.213 回答