我设置了一个按钮,用于在点击时刷新某个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>
答案 0 :(得分:0)
试试这个,它可能有效。
jQuery(function() {
jQuery("#go").on('click', function() {
jQuery("#refresh").load("space.php");
});
});
答案 1 :(得分:0)
删除<?php include('space.php'); ?>
Jquery很好。试试这个
jQuery(function() {
var i=1;
jQuery("#go").click(function() {
jQuery("#refresh").html(i);
i++;
});
});
确保space.php
位于同一台服务器上。第二件事是.load
不是php include
的替代品。使用jQuery Ajax