我希望“注册”按钮在单击时重定向到另一个页面。我尝试通过 block 和内联为此代码添加 href,但都不起作用。为什么?
<head>
<script>
function terms_changed(termsCheckBox){
//If the checkbox has been checked
if(termsCheckBox.checked){
//Set the disabled property to FALSE and enable the button.
document.getElementById("submit_button").disabled = false;
document.getElementById("submit_button").style.opacity = 1;
} else{
//Otherwise, disable the submit button.
document.getElementById("submit_button").disabled = true;
document.getElementById("submit_button").style.opacity = 0.3;
}
}
</script>
</head>
<form method="post">
<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike" onclick="terms_changed(this)">
<label for="vehicle1"> I have a bike</label><br>
<input type="checkbox" id="vehicle2" name="vehicle2" value="Car" onclick="terms_changed(this)">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat" onclick="terms_changed(this)">
<label for="vehicle3"> I have a boat</label><br>
<div>
<button type="submit" id="submit_button" style="background-color:#32CD32;color:white" disabled="">Sign Up</button>
</div>
</form>
最佳答案
该按钮是表单的提交操作。您必须向表单开始标记添加一个操作,例如:action="/test/"
。
然后表单将与您的表单数据一起重定向(意味着提交)到/test/
。将 /test/
更改为您想要的目的地。
希望这有帮助!
关于javascript - 如何将 "Sign Up"按钮重定向到另一个页面?通过 <script> block 或内联向按钮添加 href 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60784653/