【问题标题】:Div Refresh Working Only Oncediv 刷新只工作一次
【发布时间】:2012-05-13 16:49:44
【问题描述】:

我有一个按钮设置为在单击某个 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>   

【问题讨论】:

  • 将代码粘贴到问题中而不是小提琴中,因为无论如何代码都无法在小提琴中测试。
  • 好吧,在 JS Fiddle 上,&lt;?php /*...*/ ?&gt; 不会做任何事情,而且你正试图在 MooTools 下运行 jQuery。
  • 添加代码而不是小提琴。

标签: javascript load refresh


【解决方案1】:

删除&lt;?php include('space.php'); ?&gt;
Jquery 很好。测试一下

    jQuery(function() {
    var i=1;
    jQuery("#go").click(function() {
        jQuery("#refresh").html(i);
        i++;
    });
});​

jSfiddle

确保space.php 在同一台服务器上。第二件事是.load 不是php include 的替代品。使用jQuery Ajax 执行此操作

【讨论】:

    【解决方案2】:

    试试这个,它可能会工作。

    jQuery(function() {
        jQuery("#go").on('click', function() {
            jQuery("#refresh").load("space.php");
        });
    });​
    

    【讨论】:

      猜你喜欢
      • 2015-12-11
      • 2014-06-20
      • 1970-01-01
      • 1970-01-01
      • 2011-02-04
      • 2012-03-17
      • 2022-07-06
      • 2011-08-06
      • 1970-01-01
      相关资源
      最近更新 更多