简体   繁体   English

提交表单后重定向页面-Javascript

[英]Redirect the Page after Form is Submitted - Javascript

Q1 . Q1 How could I place a code that can redirect the page after the form submitted?? 提交表单后,如何放置可以重定向页面的代码?

Q2 . Q2 I am looking some article about return value , anyone please recommend some good article for me. 我正在寻找有关return value文章,请任何人为我推荐一些好文章。

    <form method="post" name="formName">
    <input type="text" value="Name" name="cName">
        <br>
    <input type="submit" onClick="return fValidator(this)">
    </form>


<script language="javascript1.8.5" type="text/javascript">

function fValidator(){
    var vName = document.formName.cName;
    var nameReg = /^[a-zA-Z]+$/;

    if (vName.value != ''){
        if (vName.value.match(nameReg)){
            alert("Your form is sumitted now!");
            return true;
            location.replace("http://www.w3schools.com");

        }   else{
                alert("Alphabet only!");
                return false;
            }
    }   else{
            alert("Fill the mandatory field!");
            return false;
        }
}

</script>

Use "onsubmit". 使用“ onsubmit”。

Eg: <form onsubmit="myFunction()"> 例如: <form onsubmit="myFunction()">

This lets you to control the page behaviour after submitting the form. 这使您可以在提交表单后控制页面的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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