如何使用JS / Jquery清除div容器的内容? [英] How to clear content of div container using JS/Jquery?
问题描述
我一直在开发一些页面,我需要清除一些div的内容:
I have been developing some page and I need to clear a content of some div:
<table>
<tbody>
<div class="records_content">
<?php
$i=0;
foreach ($records as $record) {
echo "<tr class = 'output' style='border-bottom: 1px dotted silver;'>";
echo "<td width='400'>" . strip_tags($record['language_value']) . "</td>";
if ($record['approved_translation'])
{
echo "<td width='200' height='30'><div class='field' id='".$record['label_value']."/".$record['language_id']."'>".
strip_tags($record['approved_translation']['language_value'])."</div></td><td><button class='btn btn-info' id='{$record['label_value']}/{$record['language_id']}' href='#'>More...</button>"."</td>";
}
else
{
echo "<td width='200'>"."<div id='".$record['label_value']."/".$record['language_id']."'><span class='no_translate'>Not translated</span></div>" . "</td>";
}
echo '</tr>';
$i++;
}
?>
</div>
</tbody>
</table>
一段JS代码:
$(".page_button").click(function () {
$.post("http://"+document.location.host+"/index.php/welcome/update_records_set/"+this.id,
function(data)
{
alert('123');
$(".records_content").empty();
});
});
这个脚本有效,因为我看到'123'通知,但div容器有'.records_content'类目前尚不清楚。请告诉我,我该如何解决?谢谢。
This script works, because I see '123' notification, but div container with '.records_content' class isn't clear. Please, tell me, how can I fix it? Thank you.
更新:
现在可行。但是我有一个新的分页问题:
UPDATE: Now it works. But I have a new problem with pagination:
<br><b>Page:</b><br/>
<?php
for($i=0; $i<$count; $i++)
{
if ($i==0)
{
echo "<div class='selected_page_button'>".($i+1)." "."</div>";
}
else
{
echo "<div class='page_button'>".($i+1)." "."</div>";
}
}
?>
更改按钮类别的代码:
$(".page_button").click(function () {
$(".selected_page_button").attr("class", "page_button");
$(this).attr("class", "selected_page_button");
});
它可以在没有第一个按钮的情况下正常运行。创建页面后,将选择第一页。当我点击2时,1很简单,选择2。所有按钮都没有1同样的事情:如果我点击2(或其他),那么我不能先点击! 1更改了它的视图但不改变行为,因为简单按钮是可点击的,所选按钮不可点击!
It works correctly for all buttons without first. When my page is created the first page is selected. When I click by "2", then "1" is simple and "2" is selected. The same thing is with all buttons without "1": if I click by "2" (or other one) then I can't click by first! "1" changes it's view but doesn't change behavior, because simple button is clickable and selected button is not clickable!
推荐答案
确实使用 .empty()
作为你的代码状态,除了在警报后清除。请参阅此处: http://jsfiddle.net/YPLeB/
It does clear using .empty()
as your code already states, except that it clears after the alert. See here: http://jsfiddle.net/YPLeB/
单击确定后, DIV
将按预期清除。
After you click "OK", the DIV
is cleared as expected.
这篇关于如何使用JS / Jquery清除div容器的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!