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>