0

我正在显示来自数据库的数据,我想在用户单击特定复选框时刷新结果。

我已将名称属性设置为复选框并尝试使用isset,但这不起作用,因为我实际上没有表单并使用分页在同一页面上显示结果。单击复选框而不使用时如何加载新结果<form>

这是我用来刷新页面的javascript(不是结果)

<script type="text/javascript">
    var reloading;

    function checkReloading() {
        if ( window.location.hash == "#autoreload" ) {
            reloading=setTimeout("window.location.reload();", 100);
            document.getElementById("reloadCB").checked=true;
        }
    }

    function toggleAutoRefresh( cb ) {
        if ( cb.checked ) {
            window.location.replace("#autoreload");
            reloading=setTimeout("window.location.reload();", 100);
        } else {
            window.location.replace("#");
            clearTimeout( reloading );
        }
    }

    window.onload=checkReloading;
</script>

这是第一个我尝试$_POST检查复选框是否被选中但无法工作的php,我也尝试过$_GET同样的事情。问题是即使选中了复选框,下面的代码也会显示表二忽略表一的结果。

try {    
    if ( isset( $_GET["size"] ) ) {
        $paginate = new pagination($page, 'SELECT * FROM test1 ORDER BY id desc', $options); exit();    
} else { 
        $paginate = new pagination($page, 'SELECT * FROM test2 ORDER BY id desc', $options);    
}
} catch( paginationException $e ) {
    echo $e;
    exit();
}

html

<input type="checkbox"  name="size" onclick="toggleAutoRefresh(this);" id="reloadCB">
4

1 回答 1

0

嗨,你可以试试这个:

function toggleAutoRefresh( cb ) {
    if ( cb.checked ) {
        window.location.replace("#autoreload");
        reloading=setTimeout(function(){
            // get the current url and append the parameter
            var url = window.location.href + "?size=1";
            window.open(url, '_self'); //open url
            }, 100);
    } else {
        window.location.replace("#");
        clearTimeout( reloading );
    }
}

希望这可以帮助。

编辑以包括 window.open 的第二个边界

于 2013-08-08T07:34:41.593 回答