Press enter to submit the form!

Source: Internet
Author: User

I met in the project today,Press ENTER key AjaxSubmit in the background!

Not at the beginning. No<Input type = "Submit">How can I implement carriage return and submit! Only one<AClass= "Userbut"ID= "Userbut"Href= "Javascript: void (0 );">Submit& Nbsp;Submit</A>.

CheckedBaidu, FoundAnswer:

1,If there isType = "submit",The enter key takes effect..
2,If there is only oneType = "text"OfInputNo matter what type the button is,The enter key takes effect..

 <  Form  >     <  Div  Class  = "P_box lxuser"  >              <  Div Class  = "Userborder"  >                  <  H2  >  Enter email  </  H2  >                  <  Div  Class  = "Usertable"  >                      <  Lable For  = "Email"  > <  Span  > Email: </  Span  >  </  Lable  >                      <  Input  Type  = "Text"  Name  = "Email" ID  = "Email"   />                      <  A  Class  = "Userbut"  ID  = "Userbut"  Href  = "Javascript: void (0 );"  > Submit & Nbsp; Submit </  A  >                 </  Div  >              </  Div  >     </  Div  >  </  Form  > 

JSCodeAs follows:

<SCRIPT type = "  Text/JavaScript  " >$ (Function () {$ (  "  : Input [type = text]  " ). BIND ( "  Blur  "  , Function (){  VaR _ This = $ ( This  );  If (_ This. Val (). Length = 0  ){  Return  False  ;}  Else  {  If (_ This. Val (). Match (/^ \ W + (-\ W +) | (\. \ W +) * \@@ [A-Za-z0- 9 ] + (\. |-) [A-Za-z0- 9 ] +) * \. [A-Za-z0- 9 ] + $/) = Null  ) {$ (  "  . Userred  " ). Show (). Find ( " # Textfont  " Pai.html ( "  Enter the correct email address.  "  );  Return   False  ;}  Else  {$ (  "  . Userred  "  ). Hide ();  Return  True  ;}}  Return   True  ;})  //  Submit a table as an operation          VaR Submitform = Function (){  VaR Data = $ ( "  Form  "  ). Serialize (); $. ajax2 ({URL:  ' @ URL. Action ("ensureyouremail", "findpass ")  '  , Data: data, type:  "  Post  "  , Datatype:  "  JSON  "  , Success: function (data ){  If  (Data. Code) {location. href =Data. href ;}  Else  {$ (  "  . Userred  " ). Show (). Find ( "  # Textfont  "  Pai.html (data. msg) ;}, error: function () {alert (  "  Error!  " );}})}  //  Enter key submission form $ ( "  Form  "  ). Submit (function () {submitform ();  Return   False  ;})  //  Click the button to submit the form $ ( "  # Userbut  " ). Click (function () {$ (  "  : Input [type = text]  " ). Trigger ( "  Blur  "  );  If ($ ( "  . Userred: visible  " ). Length> 0 | $ ( "  # Email " ). Val () = "" | $ ( "  # Email  " ). Val () = Null  ){  Return   False  ;} Submitform ();})}) </SCRIPT>

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.