Javascript 刷新没有id的div的内容
我正在尝试向表中添加刷新按钮。我目前正在使用Javascript 刷新没有id的div的内容,javascript,jquery,database-connection,Javascript,Jquery,Database Connection,我正在尝试向表中添加刷新按钮。我目前正在使用 var $target = $(this).parent().parent().next('.box'); $target.load("$site #" +$target.prop("nodeName"); 页面上有许多.框。当我使用.load()时,是否有一种方法可以通过DOM中的位置引用特定的.box 另外,是否有方法延迟表加载,告诉数据库中的更新已完成?我在加载内容之前处理了对数据库的更新,但它似乎仍然像没有发生数据库更新一样加载,需要刷新
var $target = $(this).parent().parent().next('.box');
$target.load("$site #" +$target.prop("nodeName");
页面上有许多.框。当我使用.load()时,是否有一种方法可以通过DOM中的位置引用特定的.box
另外,是否有方法延迟表加载,告诉数据库中的更新已完成?我在加载内容之前处理了对数据库的更新,但它似乎仍然像没有发生数据库更新一样加载,需要刷新
谢谢您可以稍微重新组织Html,例如将.box内容包装在.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>
否则,只要HTML保持每个部分的布局,您现在拥有的.parent.parent样式就可以工作;您正在使用parent.parent.next代码引用它在DOM中的位置,因为您知道这将是正确的框内容div的位置
编辑:详细说明为什么find将与html结构一起工作。find和类似的。children元素只查看子元素:from
根据您向我展示的示例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>
将始终获得正确的元素。如果始终以相同的为目标,则find将保留在父元素中。框为什么不为其分配一个ID并以该ID为目标?我希望代码可重用。我有三个框在我的网页上,我想能够分别刷新。我需要我的$(刷新btn)。单击。。。为链接所在的框工作。是否为每个框设置单独的刷新按钮以分别刷新它们?你能为这个发布一些HTML结构吗?我想刷新按钮链接到当前框。每个框都是相同的按钮,但按钮的不同实例(?)将有多个框内容。在选择正确的产品时会发现问题吗?这仍然没有解释我如何加载$target.load(mysite+‘正确的框内容’)
<.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)
});