奇怪!!!当光标在文本框中时按"回车"键页面竟然提交,怎样禁止这种文本框回车提交事件但又不影响button按钮的回车提交? <input onkeydown="if(event.keyCode==13){event.keyCode=0;return false}"> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 meizz(梅花雨)你的方法我早就试过了,如果按你那样写则表单中所有的按钮都不再响应回车事件?这不是我想要的。我想做的效果是:只有焦点在按钮上按回车才会提交页面,焦点在其它位置时按回车键不能提交页面?我看到有的网页也没写你那句话就可以屏蔽text的回车事件,但又不会屏蔽按钮的回车事件,请问这是怎么回事? 总不能每个text都加一句onkeydown="if(event.keyCode==13){event.keyCode=0;return false}"吧?那也太麻烦了?我看到有的网页也没写你那句话就可以屏蔽text的回车事件,但又不会屏蔽按钮的回车事件,请问这是怎么回事? <input type="button" value="提交" onclick="form1.submit();"> <script>function ifenter(){if(event.keyCode==13)if(event.srcElement.type=="submit")form1.submit();elsereturn false;}document.onkeydown=ifenter;</script><form name=form1><input><input><input type=checkbox><input type=submit></form> 有两种情况使得当光标在文本框中时按"回车"键页面竟然提交:1.页面只有一个text-input框。2.页面有一个submit类型的button。如果是第一种情况,可能需要用梅花雨的方法如果是第二种情况,把type=submit改成type=button就可以了不知是不是这么回事?错了勿怪! 原来楼主是想偷懒, 不想在每个文本框写那句代码呀!!<body onkeydown="keydown()"><form><input name=qq><input type=submit value=ok name=ok></form><script language="JavaScript"><!--function keydown(){ var k = window.event.keyCode; var e = window.event.srcElement; if (e.type == "text" && k == 13) { window.event.keyCode = 0; window.event.returnValue = false; }}//--></script> 我看到有的网页(其中有的也只有一个text)什么keydown(),keypress()也没写就可以屏蔽text的回车事件,但又不会屏蔽按钮的回车事件,请问这是怎么回事? =========================================================有两种情况使得当光标在文本框中时按"回车"键页面竟然提交:1.页面只有一个text-input框。2.页面有一个submit类型的button。如果是第一种情况,可能需要用梅花雨的方法如果是第二种情况,把type=submit改成type=button就可以了========================================================= 我看到有的网页(只有一个text)什么keydown(),keypress()也没写? beihua(白话):我看到有的网页(只有一个text)什么keydown(),keypress()也没写?---------------------------能不能拷过来看一看?也有可能JK的经验之谈错了。 下面的页面只有一个text<html><head><title>编辑字典信息</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><link rel="stylesheet" href="../putong_1t"></head><body> <div class='TitleBar' >字典信息维护</div><br><table align="center" width="260" class="InputFrameMain"><tr><td><table border=0 align=center cellpadding=0 cellspacing=0 style="Margin:5px 5px 5px 5px"><tr class=InputFrameLine> <td class="InputLabelCell" align="center" width="60"> 字典内容 </td> <td class="InputAreaCell" align="center" width="150"> <input id="txtNR" class="input" maxLength="20" name="txtNR" value="" style="width:100%" > <input id="txtDM" type="hidden" name="txtDM" value=""> <input id="txtZDBM" type="hidden" name="txtZDBM" value="jgbz"> </td></tr><tr class='InputFrameButtonLine'> <td align="center" colspan="2" > <input class="button" onclick="vbscript:Save_onclick" type="button" value="保存" id="button1" name="button1"> <input type="button" class="button" onclick="vbscript:Cancel_onclick" value="返回" id="button2" name="button2"> </td></tr></table></td></tr></table> </body> <script ID="clientEventHandlersVBS" LANGUAGE="vbscript"> <!-- 'window.txtNR.value = replace(window.txtNR.value," "," ") function Save_onclick if Trim(txtNR.value)="" then msgbox "字典内容不能为空。",,"提示" exit function end if if msgbox("是否要保存修改?",vbQuestion+vbYesNo,"提示") =vbNo then exit function end if if txtDM.value="" then self.location="fjhbgl_zdwh_save.asp?ZDBM=" & txtzdbm.value & "&sZDMC=" & txtNR.Value else self.location="fjhbgl_zdwh_save.asp?ZDBM=" & txtzdbm.value & "&sZDMC=" _ & txtNR.Value & "&sDM=" & txtdm.value end if End functionfunction Cancel_onclick history.back(1) end function --> </script> 我晕呀晕, 我说是怎么回事呢, 原来这些个文本框呀, 按钮呀, 其实就根本不是什么表单, 你自己看看代码里有没有 form 这个表单标签否??? 既然不是表单, 当然回车的时候就不会提交了. 害得我被你弄得云里雾里的. 这段代码里, 只是直接将要传递的内容定到链接里并赋给location, 功能类似于get提交:self.location="fjhbgl_zdwh_save.asp?ZDBM="& txtzdbm.value &"&sZDMC="& txtNR.Value这段代码并没有组成表单. 文件上传问题 jQuery添加地图标注无法再iframe中运行 javascript方法区别 为什么这个oclick在火狐下跳转,在IE下不跳转? 原来都是iframe搞得鬼,害我找了半天,大家引以为鉴 数组 大家都用什么软件写JavaScript? 谁能帮我把此程序改成能设置cookie有效期为1年的 input问题 字符串变量怎样转换成对象变量,在线等待 好久没到这里来了,不知道有没有人认识我:)) 顺便问个大大的问题;// 如何实现在IFRAME里粘贴时,粘贴在当前光标所在位置?
function ifenter()
{
if(event.keyCode==13)
if(event.srcElement.type=="submit")
form1.submit();
else
return false;
}
document.onkeydown=ifenter;
</script>
<form name=form1>
<input>
<input>
<input type=checkbox>
<input type=submit>
</form>
1.页面只有一个text-input框。
2.页面有一个submit类型的button。如果是第一种情况,可能需要用梅花雨的方法
如果是第二种情况,把type=submit改成type=button就可以了不知是不是这么回事?
错了勿怪!
<form>
<input name=qq>
<input type=submit value=ok name=ok>
</form><script language="JavaScript"><!--
function keydown()
{
var k = window.event.keyCode;
var e = window.event.srcElement;
if (e.type == "text" && k == 13)
{
window.event.keyCode = 0;
window.event.returnValue = false;
}
}
//--></script>
有两种情况使得当光标在文本框中时按"回车"键页面竟然提交:
1.页面只有一个text-input框。
2.页面有一个submit类型的button。如果是第一种情况,可能需要用梅花雨的方法
如果是第二种情况,把type=submit改成type=button就可以了
=========================================================
---------------------------能不能拷过来看一看?
也有可能JK的经验之谈错了。
<head>
<title>编辑字典信息</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="../putong_1t">
</head>
<body>
<div class='TitleBar' >字典信息维护</div>
<br>
<table align="center" width="260" class="InputFrameMain">
<tr><td><table border=0 align=center cellpadding=0 cellspacing=0 style="Margin:5px 5px 5px 5px">
<tr class=InputFrameLine>
<td class="InputLabelCell" align="center" width="60">
字典内容
</td>
<td class="InputAreaCell" align="center" width="150">
<input id="txtNR" class="input" maxLength="20" name="txtNR" value="" style="width:100%" >
<input id="txtDM" type="hidden" name="txtDM" value="">
<input id="txtZDBM" type="hidden" name="txtZDBM" value="jgbz">
</td>
</tr>
<tr class='InputFrameButtonLine'>
<td align="center" colspan="2" >
<input class="button" onclick="vbscript:Save_onclick" type="button" value="保存" id="button1" name="button1">
<input type="button" class="button" onclick="vbscript:Cancel_onclick" value="返回" id="button2" name="button2">
</td>
</tr>
</table>
</td></tr></table>
</body>
<script ID="clientEventHandlersVBS" LANGUAGE="vbscript">
<!--
'window.txtNR.value = replace(window.txtNR.value," "," ")
function Save_onclick
if Trim(txtNR.value)="" then
msgbox "字典内容不能为空。",,"提示"
exit function
end if
if msgbox("是否要保存修改?",vbQuestion+vbYesNo,"提示") =vbNo then
exit function
end if
if txtDM.value="" then
self.location="fjhbgl_zdwh_save.asp?ZDBM=" & txtzdbm.value & "&sZDMC=" & txtNR.Value
else
self.location="fjhbgl_zdwh_save.asp?ZDBM=" & txtzdbm.value & "&sZDMC=" _
& txtNR.Value & "&sDM=" & txtdm.value
end if
End function
function Cancel_onclick
history.back(1)
end function
-->
</script>
self.location="fjhbgl_zdwh_save.asp?ZDBM="& txtzdbm.value &"&sZDMC="& txtNR.Value
这段代码并没有组成表单.