Javascript form validation and Window details

  • 2020-03-30 04:35:34
  • OfStack

I. form validation form

1. Create a new form:


<form id="id It's unique, it's not repeatable " name= "Repeatable", method="post/get",action=" Where is the destination or address, the server that handles it, the text, etc ">
//Method 1: post has no length limit after submission, and the encoded content is not visible. < br / > //Method 2:get submissions have a length limit, and the encoded content is visible in the address bar
( input Elements)
</form>

2, the role of the form: to be able to transfer the url, data to the database.

3. Action properties: action and confirm button

When the user clicks the confirm button, the contents of the form are passed to another file. The action property of the form defines the name of the destination file. This file, defined by the action properties, is usually associated with the input data received.

Javascript window -- browser object model

1. Window object

2. JsPopupAlert message box

< The input name = "" type =" submit "  Onclick ="return tijiao()" value=" submit "/> < ! -- return-->

< ! --Js message box -->

1) the use of confirm box


<!--1. Confirmation box confirm The use of the -->
<script>
function tijiao()
{
var zhi=confirm(" Whether to commit ");
if (zhi)
{
return true;
}
else
{
return false;
}
}
</script>
<!-- When the form calls a function, add return Otherwise it won't work

2) prompt prompt


<input name="" type="submit"  onclick="return tijiao()" value=" submit "/><!-- When calling a method return-->
!--2. Prompt box prompt The use of the -->
<script>
function tijiao()
{
var zhi=prompt(" Whether to commit ");<!-- After clicking the submit button, it appears prompt Script prompt -->
if (zhi)
{
return true;
}
else
{
return false;
}
}
</script>

3) the use of alert


<form action="" method="get">
<label> Please enter your email address: </label>
<input name="" type="text" id="youxiang"/>
<input name="" type="submit" value=" submit 2" onclick="y()" />
</form>
function y()
{
var yx=new RegExp(/^[0-9|A-z|_]{1,17}@[A-z|0-9]{1,5}.(com|cn|net|org|cc)$/);
var shuru=document.getElementById("youxiang").value; <!-- Define a variable that calls the whole thing function,, You have to write the variable at function Within the -->
if(yx.test(shuru))<!--test Regular expression methods -->
{
alert("zhengque");
}
else
{
alert("cuowu");
}
}
</script>

3. Timing method

SetTimeout (); Execute code at some point in the future -- using recursive methods

ClearTimeout (); To cancel the setTimeout ();


Related articles: