我有一个按钮设置为在单击某个 div 时刷新它。问题是它只能工作一次。
单击按钮时我需要刷新的 div:
<div id="refresh">
<?php include('space.php'); ?>
</div>
刷新 div 的脚本:
jQuery(function() {
jQuery("#go").click(function() {
jQuery("#refresh").load("space.php");
});
});
和 space.php 的内容:
<?php
/* get disk space free (in bytes) */
$df = disk_free_space("/home");
/* and get disk space total (in bytes) */
$dt = disk_total_space("/home");
/* now we calculate the disk space used (in bytes) */
$du = $dt - $df;
/* percentage of disk used - this will be used to also set the width % of the progress bar */
$dp = sprintf('%.2f',($du / $dt) * 100);
/* and we formate the size from bytes to MB, GB, etc. */
$df = formatSize($df);
$du = formatSize($du);
$dt = formatSize($dt);
function formatSize( $bytes )
{
$types = array( 'B', 'KB', 'MB', 'GB', 'TB' );
for( $i = 0; $bytes >= 1024 && $i < ( count( $types ) -1 ); $bytes /= 1024, $i++ );
return( round( $bytes, 2 ) . " " . $types[$i] );
}
?>
<table class='ipb_table' cellspacing='1'>
<tr>
<td class='row2' colspan='2'>
<div class='progress'>
<div class='prgbar'></div>
</div>
</td>
<tr>
<td class='row2'>
Disk Space:
</td>
<td class='row2'>
<?php echo "$dt"; ?>
</td>
</tr>
<tr>
<td class='row2'>
Free:
</td>
<td class='row2'>
<?php echo "$df"; ?>
</td>
</tr>
<tr>
<td class='row2'>
Used:
</td>
<td class='row2'>
<?php echo "$du"; ?>
</td>
</tr>
<tr>
<td class='row2' colspan='2' align='center'>
<a class='ipsButton' id='go'>Refresh<a>
</td>
</tr>
</table>