[英]Refresh div with Jquery on click
可以說我有一個包含div和mysql數據的頁面。 例如下面的代碼:
<div id="example">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>#</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<?php $num_rows=1 ; // store the record of the "tblstudent" table into $row while ($row=m ysqli_fetch_array($result)) { // Print out the contents of the entry echo '<tr>'; echo '<td>' . $num_rows . '</td>'; echo '<td>' . $row[ 'name'] . '</td>'; $num_rows++;
} ?>
</tbody>
</table>
</div>
如果在這種情況下,我只想刷新頁面的某些部分<div id="example">
,我該如何只用一個頁面而不使用.load()
或$.post
做到這一點。 實際上有可能嗎?
您發布的是PHP-在PHP中根本無法更新頁面。 您可能會使用JavaScript來做到這一點。
如果要刷新頁面的特定部分,通常可以使用AJAX來完成( $.ajax
或.load()
)。 由於您不希望/無法使用AJAX,因此IFRAME實際上是唯一的其他方法。 在單獨的頁面中將內容框架化,然后通過IFRAME將其包括在內。 您可以使用以下兩種方法之一來刷新它:
document.getElementById('#FRAME').contentDocument.location.reload(true);
var iframe = document.getElementById(FrameId);
iframe.src = iframe.src;
您在頁面加載時所做的克隆對象。 您需要采用全局變量。
var cloneObj;
$(document).ready(function (){
cloneObj= $("#example1").clone();
});
現在,每當您需要刷新該元素時,只需調用以下代碼即可。
$("#example1").replaceWith(cloneObj.clone());
我在以前的答案中使用了此代碼。 請檢查此FIDDLE
希望對您有幫助。 如果不是,請詢問。 我會再試一次
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.