English 中文(简体)
在新闻进入关键媒体时提交超文本
原标题:HTML form submit when press enter key

我的表格是,如果我点击了提交国,它应该提交。 即使我是在文字领域,并施加压力,形式应该提交。 谁能告诉我为什么发生这种情况?

<html>
    < body>

    <form name="input" action="html_form_action.asp" method="get">
        First name: <input type="text" name="FirstName"  /><br />
        Last name: <input type="text" name="LastName" /><br />
        <input type="submit" value="Submit" />
    </form> 

    </body>
</html>
最佳回答

这是正常的行为。 浏览器可以由用户提交表格,要求进入文字领域;它使多种形式更加方便。

问题回答

this is the default behavior of submit button. submit task fire when you press the enter key. if you do not want that you can prevent that. use below code in the relevant tag for that.

event.preventDefault()

页: 1

onkeydown= if ((event.keyCode == 13 && document.getElementById("field_0").value!="") &&  event.which == 13){   
                document.getElementById("field_1").focus();
                event.preventDefault();
} 

Quentin说,这是一种正常的行为。 但是,如果你想在进入关键媒体之后阻止提交,那么你可以这样做:

<SCRIPT LANGUAGE="javascript"> 
function testForEnter() 
 {    
   if (event.keyCode == 13) 
   {        
      event.cancelBubble = true;
      event.returnValue = false;
  }
} 
</SCRIPT> 

详情见





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签