javascript - 如何将 "Sign Up"按钮重定向到另一个页面?通过 <script> block 或内联向按钮添加 href 失败

标签 javascript html

我希望“注册”按钮在单击时重定向到另一个页面。我尝试通过 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"按钮重定向到另一个页面?通过 &lt;script&gt; block 或内联向按钮添加 href 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60784653/

相关文章:

javascript - 刷新 select2 下拉列表

javascript - match() 函数输入的 TypeScript "type"是什么

所有列表项的 Javascript/JQuery 相同下拉菜单

html - 响应式 html 在我的 iphone 4s 上显示平板电脑 css 设计而不是手机?

html - 网站站点在 Dreamweaver 中看起来不错,但是

Java - 从字符串中提取html信息

javascript - 添加跳过按钮以快进 .fadeIn/.fadeOut?

Javascript - 一个函数的变量会干扰另一个函数

javascript - 如何从字符串调用和执行运算符?

javascript - 脚本标签内的 HTML?