简体   繁体   中英

Why can't my javascript redirect the following code, I've tried multiple solution that i found in StackOverFlow

I have tried multiple of things making the code to redirect, my teacher told me that I need to use method POST, while the following code is the working one which the method get, if I change the method to POST it cannot redirect. I tried using the location.href inside my code, it doesn't seem to work at all. I even tried putting the return false in my javascript. May I know how can I fix these issues?

The following are my code for my form

<form action="/Membership/member-profilepage/member_home.html">
                <div class="row">
                    <div class="col-1">
                        <input type="text" name="username" placeholder="Username" required>
                        <input type="password" name="password" placeholder="Password" required>
                        <input type="checkbox" id="rmbpw" name="rmbpw" value="rmbpw">
                        <label for="rmbpw" id="rmbpw" name="rmbpw">&nbsp;&nbsp;&nbsp;RememberMe</label>
                        <input type="submit" value="Login" onclick="login()">
                    </div>
                    <script src="login.js"></script>
                </div>
            </form>

This will be the code for my javascript

function login(){
    alert("Login Successfully!");
    
}

Oh, Guys, I figure out an answer after doing a couple more research and trying a few more things. I cannot use input type="submit". Hence, I need to use input type="button" to do the redirection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM