我正在显示数据库中的数据,我希望在用户单击特定复选框时刷新结果。
我已经将name属性设置为复选框,并尝试使用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>
这是php,我第一次尝试$_POST
来检查复选框是否被选中,但这不起作用,我也尝试了$_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">
嗨,你可以试试这个:
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 );
}
}
希望这能有所帮助。
编辑为包括窗口的第二个周长。打开