<input type=text id="txt">
<input type=button id="go" value="go" onclick="alert('go')">
<script>
document.onkeydown=ShortcutKey;
function ShortcutKey()
{
if(window.event.keyCode==13)
{
go.focus();
}
}
</script>
<input type=button id="go" value="go" onclick="alert('go')">
<script>
document.onkeydown=ShortcutKey;
function ShortcutKey()
{
if(window.event.keyCode==13)
{
go.focus();
}
}
</script>
<html>
<body>
<script>
function start(){alert('fk')}
function document.body.onkeypress(){
if(event.keyCode==13)
start();
}
</script><input type="text" name="br1" size="3">
</input>
<button onclick="start()" accesskey="s">Start</button>
</body>
</html>
这个例子中点击回车就可以做一个我想要的动作.按这个思路我重新做了一下改变如下,可是还是没我想要的结果.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Flash Time Setting</title>
</head>
<body topmargin="45" leftmargin="80">
<Script language="JavaScript">
function isNumeric(str,small,max)
{
if (!isNaN(str) && str >= small && str <= max){
return true
}
return false
}
function saveChanges()
{
if (!(isNumeric(document.flashform.FTime1.value,4,255)))
{
alert('The Max Flash Time value should be between 4 and 255 ! ');
document.flashform.FTime1.value=document.flashform.FTime1.defaultValue;
document.flashform.FTime1.focus();
return false;
}
document.flashform.FTime1.value=parseInt(document.flashform.FTime1.value,10);
alert('the value is : '+document.flashform.FTime1.value);
return true;
} function doit()
{
alert("do it");
}
function document.flashform.FTime1.onKeyPress()
{
if(event.KeyCode==13) doit();
}
</Script>
<p><font face="Times New Roman" size="6" color="#000080">Flash Time Setting</font></p>
<table border="0" width="500" id="table1">
<tr>
<td><font face="Arial" size="2">You could set the flash time in this
page.</font></td>
</tr>
<tr>
<td><hr></td>
</tr>
</table><table border="0" width="500" id="table2">
<tr>
<td> </td>
</tr>
<tr>
<td>
<form name="flashform">
<table border="0" width="100%" id="table3">
<tr>
<td width="27%" bgcolor="#000080">
<font face="Arial" size="2" color="#FFFFFF">Max Flash Time:</font></td>
<td width="71%" bgcolor="#000080">
<font size="2" face="Arial" color="#FFFFFF"> <!--t1--><input type="text" name="FTime1" size="3" value="134" maxlength="3">
x 10MS (4~255)</font></td>
</tr>
<tr>
<td width="145"> </td>
<td> </td>
</tr>
<tr>
<td width="145"> </td>
<td> <input type="submit" value="Submit" name="Apply" onClick="return saveChanges()" >
<input type="reset" value="Reset" name="Clear"></td>
</tr>
</table><p> </p>
</form>
<p> </td> </tr></table>
</body>
</html>
请问各位高人,我该如何做呢?再一次表示感谢.谢谢.
<body>
<input type=text id="txt" NAME="txt" onkeypress="ShortcutKey();">
<input type=button id="go" value="go" onclick="alert('go')" NAME="go">
</body>
</html>
<script language=javascript>function ShortcutKey()
{ if(window.event.keyCode==13)
{
go.click(); }}
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Flash Time Setting</title>
</head>
<Script language="JavaScript">
function isNumeric(str,small,max)
{
if (!isNaN(str) && str >= small && str <= max){
return true
}
return false
}
function saveChanges()
{
if (!(isNumeric(document.flashform.FTime1.value,4,255)))
{
alert('The Max Flash Time value should be between 4 and 255 ! ');
document.flashform.FTime1.value=document.flashform.FTime1.defaultValue;
document.flashform.FTime1.focus();
return false;
}
document.flashform.FTime1.value=parseInt(document.flashform.FTime1.value,10);
alert('the value is : '+document.flashform.FTime1.value);
return true;
}</Script>
<body topmargin="45" leftmargin="80">
<p><font face="Times New Roman" size="6" color="#000080">Flash Time Setting</font></p>
<table border="0" width="500" id="table1">
<tr>
<td><font face="Arial" size="2">You could set the flash time in this
page.</font></td>
</tr>
<tr>
<td><hr></td>
</tr>
</table><table border="0" width="500" id="table2">
<tr>
<td> </td>
</tr>
<tr>
<td>
<form method="POST" action=/flashset.cgi name="flashform">
<table border="0" width="100%" id="table3">
<tr>
<td width="27%" bgcolor="#000080">
<font face="Arial" size="2" color="#FFFFFF">Max Flash Time:</font></td>
<td width="71%" bgcolor="#000080">
<font size="2" face="Arial" color="#FFFFFF"> <!--t1--><input type="text" name="FTime1" size="3" value="134" maxlength="3" onKeyDown="if(event.keyCode==13) return saveChanges()">
x 10MS (4~255)</font></td>
</tr>
<tr>
<td width="145"> </td>
<td> </td>
</tr>
<tr>
<td width="145"> </td>
<td> <input type="submit" value="Submit" name="Apply" onClick="return saveChanges()" >
<input type="reset" value="Reset" name="Clear"></td>
</tr>
</table><p> </p>
</form>
<p> </td></tr></table>
</body>
</html>
<input type="text" name="FTime1" size="3" value="134" maxlength="3" onKeyDown="if(event.keyCode==13) return saveChanges()"> 加了一个onkeydown的判断
应该是event.keyCode==13
注意大小写。另外,你直接这样写function document.flashform.FTime1.onKeyPress()不行吧,在加载script的时候,flashform还没有生成,会出找不到对象的错误。
function test()
{
if(event.KeyCode==13) doit();
}<input type="text" name="FTime1" size="3" value="134" maxlength="3" onkeypress="test()"> 这样试试
当页面form只有一个text-input时,回车就会将这个form submit.JK常用的解决方法:
在form 里加一个:<input style="display:none;"/>
加个text-input后,就会先执行submit按钮的onclick事件,
如果不加的话,不会执行submit的onclick事件,(应该也不会触发form的onsubmit)
中午在不经意间,给后面多加了个text如下:
<form method="POST" action=/flashset.cgi name="flashform">
<table border="0" width="100%" id="table3">
<tr>
<td width="27%" bgcolor="#000080">
<font face="Arial" size="2" color="#FFFFFF">Max Flash Time:</font></td>
<td width="71%" bgcolor="#000080">
<font size="2" face="Arial" color="#FFFFFF"> <!--t1--><input type="text" name="FTime1" size="3" value="134" maxlength="3" onKeyDown="if(event.keyCode==13) return saveChanges()">
x 10MS (4~255)</font></td>
</tr>
<tr>
<td width="145"> </td>
<td> <input type=\"HIDDEN\" name=\"aaa\"></td>
</tr>
<tr>
<td width="145"> </td>
<td> <input type="submit" value="Submit" name="Apply" onClick="return saveChanges()" >
<input type="reset" value="Reset" name="Clear"></td>
</tr>
</table><p> </p>
</form>
这是不是就是如各位高人们所说的那样的解决办法呢?感谢高人们对执行机理的讲解,谢谢.