When the page has only one text, press enter to automatically submit.

Source: Internet
Author: User

In a depressing situation, an event of automatic Ajax sending by carriage return is added to a text element on the page. However, every time you press enter, it will automatically submit the form and refresh the page, simple page htmlCodeAs follows:

Code < Html >
< Head >
< Title > Test </ Title >
< Script Language = "JavaScript" >
Function Test (){
If (Event. Which | Event. keycode ){
If (Event. Which = 13   | Event. keycode = 13 ){
Ajaxpost ();
Return   False ;
} Else {
Return   True ;
}
}
}
</ Script >
</ Head >
< Body >
< Form Name = "Test" Method = "Post" Action = "Test.htm" >
< Input Type = 'Button' Value = 'Test' Onclick = "Javascript: Test ()" >  
< Input Type = "Text" Name = "Textfield" Class = "Input" >
</ Form >
</ Body >
</ Html >

In order to solve this problem, neither of the following methods can be used to block the event or return false. Later, I checked it on the Internet. It turns out that this is a default operation of IE (but it is strange that the same is true in Firefox ). The solution is simple. You only need to add a text element to the page, which can be hidden.

 

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.