有什么方法可以用javascript清除listview吗

Is there any way to clear listview with javascript?

本文关键字:javascript 清除 listview 什么 方法      更新时间:2023-09-26
<asp:ListView ID="lvZipcodeFinder"></asp:ListView>

我正在模式弹出窗口中使用我的列表视图。因此,如果modalpopup关闭并打开,则必须清除listview。。。。那么有没有什么方法可以用javascript清除列表视图呢?必须使用javascript…清除它。。。。请帮帮我。

是的,您可以这样做:(在服务器端从DOM中删除实际项目(

只需在.aspx页面中添加一个隐藏按钮:

<asp:Button ID="btnClearListView" runat="server" 
              Text="Button" style="display:none;" 
              OnClick="btnHidden_Click" ClientIDMode="Static" />

在您的javascript中,当您调用close-modal时,您也只需要使用这些代码。

document.getElementById('btnClearListView').click();

在你的代码后面的按钮,你会有这样的东西:

  protected void btnClearListView_Click(object sender, EventArgs e)
    {
        ListView1.Items.Clear();
    }

您也可以在打开模式弹出窗口时执行同样的操作。

(在客户端使用jQuery(

这是另一种方法,但这只会使控件消失,而不是从列表视图中删除实际项目。您应该知道,如果需要删除服务器控件,则必须使用服务器端编码。

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
    $(document).ready(function () {
        $("#Submit1").click(function () {
            $("#lvZipcodeFinder_itemPlaceholderContainer").remove();
        });
    });
</script>
<input id="Submit1" type="button" value="Close Popup" />

确保ListView id与上面的javascript代码匹配,之后您需要_itemPlaceholderContainer,尽管