ASP. net1.1:
Let the text box focus as soon as it is opened on the page:
Page. registerstartupscript ("Focus", "<script language = JavaScript & gt; document. All ('text control id'). Focus () </SCRIPT> ");
Press enter to trigger the specified button event: when the focus is on the password box, press enter to trigger the btnok button event
In the pageload event:
Txtpassword. Attributes. Add ("onkeydown", "submitkeyclick ('btnok ');");
In HTML:
<Script language = "JavaScript">
Function submitkeyclick (button)
{
If (event. keycode = 13)
{
Event. keycode = 9;
Event. returnvalue = false;
Document. All ('btnok'). Click ();
}
}
</SCRIPT>
Medium 2.0:
<Form ID = "form1" runat = "server" defaultbutton = "btnquery" defaultfocus = "txtusername"> </form>
3. As the browser is constantly changing, compatibility has become a major issue. The above is no longer suitable for IE 8 and other browsers.
Currently, jquary is widely used. We recommend that you use jquary's $ ("# idname "). focus () is used to get the focus of textbox and so on. It is not only compatible with most browsers, but also highly secure.