单击按钮时跳转到另一个页面

时间:2017-12-17 16:14:18

标签: javascript html

我正在尝试这一点,当我点击一个按钮时,它会显示一条警告信息并转到另一个页面

  <script type="text/javascript">
    function password_change_function(){
       var x= document.getElementById("password_change").value;
       alert("Password is changed");
       window.location.assign("viewprofile.php");}

    </script>

html部分是:

 <form>
   <table>
        <tr>
           <td><strong>Current Password</strong></td>
           <td><strong>:</strong></td>
           <td><input type="password" name="currentpassword" value="ratul@aiub" /></td>  
        </tr>
        <tr>
           <td><strong>New Password</strong></td>
           <td><strong>:</strong></td>
           <td><input type="password" name="newpassword" value="kumar@ai" /></td>  
        </tr>
        <tr>
           <td><strong>Retype New Password</strong></td>
           <td><strong>:</strong></td>
           <td><input type="password" name="retypepassword" value="kumar@ai"  /></td>  
        </tr>
   </table>
   <p align="center"><input id="password_change" type="submit" value="Submit" onclick="password_change_function()"/></p>
   </form>

主要问题是,它显示警告信息但页面未更改

3 个答案:

答案 0 :(得分:1)

您可能想尝试像这样切换最后两个语句

window.location.assign("viewprofile.php");}
alert("Password is changed");

答案 1 :(得分:0)

试试这个

 <!DOCTYPE html>
    <html>
    <head>
    <title>Page Title</title>
    </head>
    <body>

     <script type="text/javascript">
        function password_change_function(){
           var x= document.getElementById("password_change").value;
           alert("Password is changed");
           window.location = "http://example.com/foo.php";
           }

        </script>
    <input id="password_change" type="submit" value="Submit" onclick="password_change_function()"/>
    </body>
    </html>

答案 2 :(得分:0)

您可以通过交换两行代码来实现目标:

从此:

alert("Password is changed");
window.location.assign("viewprofile.php");}

对此:

window.location.assign("viewprofile.php");
alert("Password is changed");}