簡體   English   中英

刷新沒有ID的div的內容

[英]refresh contents of div without id

我正在嘗試向表添加刷新按鈕。 我目前正在使用。

var $target = $(this).parent().parent().next('.box');
$target.load("$site #" +$target.prop("nodeName");

頁面上有很多.box。 當我使用.load()時,是否可以通過DOM中的位置引用特定的.box?

另外,是否有一種方法可以延遲表加載以告知數據庫更新已完成? 在加載內容之前,我已經處理了對數據庫的更新,但似乎仍未加載數據庫更新,因此需要刷新。

謝謝

您可以稍微重組HTML,例如將.box-content包裝在.refresh div中

<section class="col col-lg-8">
    <div class="box">
        <div class="box-header">
                <h2> <i class="fa fa-user"></i><span class="break"></span>Recently Added</h2>

            <div class="box-icon"><a class="btn-minimize" href="#"><i class="fa fa-chevron-up"></i></a>

            </div>

        </div>
        <!-- Box Header -->
        <div class="box-icon"><a class="btn-reload" href="#">reload<i class="fa fa-circle"></i></a>


        <div class="box-content">
            <table class="table table-striped table-bordered bootstrap-datatable datatable">
                <thead>
                    <tr>
                        <th>Username</th>
                        <th>Date registered</th>
                        <th>Role</th>
                        <th>Status</th>
                        <th>Actions</th>
                    </tr>
                </thead>
            </table>
        </div>
   </div>

然后var $target = $(this).parent().parent().next('.box-content'); 可以更改為:

var $target = $(this).find('.box-content');

否則,只要HTML保持每個部分的布局,您現在就應該可以使用.parent.parent樣式。 您正在使用parent.parent.next代碼在DOM中引用它的位置,因為您知道這將是正確的box-content div的位置。

編輯:詳細說明為什么find將與您的html結構.find和類似的.children元素一起使用,僅查看其后代元素:來自http://api.jquery.com/find/

根據示例HTML,您向我展示了:

<.box>
    <box descendant>
        <descendant element>
    </box descendant>
    <box descendant2>
    </box descendant2>
</box>
<.box>
    <box descendant>
        <descendant element>
    </box descendant>
    <box descendant2>
    </box descendant2>
</box>

正在做:

 $(.box).click(function(){
    $(this).find(descendant element)
});

因為.find將保留在父元素中,所以它將始終獲得正確的元素

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM