Js difference in the submit button and the

Js difference in the submit button and the

Js wrote today a verification point encounter pits the record about

 

button- push button, submit- submit button.


  submit button is a special case, but also a button, which is to submit the action automatically integrates, and submit button, both show the form of a button, the button looks are, except that the type and properties of the hair on incident response.



 

function check(){
var name = document.getElementById("name").value;
if(name == null || name == ''){
alert("用户名不能为空"); 
return false;
}
return true;
}


<form name="form" action="跳转的页面" method="post" onsubmit="return check()">
<input type="text" id="name"/>
<input type="submit" value="提交"/>
</form>

 


The above scenario, the form needs to be processed (including input validation) and then submit a JS after clicking the submit button, then usually we promote the use of button,

 

 

If you need to submit verification before submit, then return should be added before the method. onClick method will automatically be submitted without return, and will not play the role of constraints, so authentication is required to submit, please use plus return true or false.
As a landing module, first verify that the user name is empty, if empty, always click SUBMIT not submit a form from the specified page. Only to send the form and the form can no longer form the specified page to verify the value passed in.
 

 

posted @ 2019-06-11 09:44 Mr. Ching reading (...) Comments (...) edit collections

Guess you like

Origin blog.csdn.net/qq_17204441/article/details/91863396