[英]Page just reloads but doesn't redirect to the page
我只是想設置一個按鈕來重定向到主頁,但頁面只是刷新而不是重定向到主頁。
<script type="text/javascript">
function backs(){
location.replace("index.php");
}
</script>
使用location.href
代替:
<script type="text/javascript">
function backs(){
location.href = "index.php";
}
</script>
在您的按鈕中添加onClick
事件如下:
<button onClick="javascript:window.location.href='index.php">Edit</button>
能分享一下按鈕代碼嗎? HTML和JS? 我很好奇你是如何調用backs()
函數的。
此外,正如其他人所建議的, location.href
會更合適。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.