一个基础很容易的问题, 谁解决了30分送上, 顶着也送 代码不完整,按你这个代码是不可能提交的。form在只有一个text类型的input时,默认回车自动提交 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 上面说的还不完整,一个form如果没有type=submit的input,在只有一个text时回车自动提交。如果有type=submit的input,则回车都会自动提交。你的代码加上form的话应该都会自动提交。 问题如下:当焦点在div[checkid]里时,按回车键能执行提交,反之如果焦点不在div里面,按回车不做操作 ? 讲的不明白吗? <body> <div id="checkid"> <input type="text" id="1"size="20"/> <input type="text" id="2"size="20"/> <input type="text" id="3"size="20"/> </div> <input type="text" id="W_1"size="20"/> <input type="text" id="W_2"size="20"/> <input type="button" name ="button"/> </body> 这样说吧,只要当焦点在<div>里面的标签上,按回车就触发onclick()事件, 反之如果不在则不做操作如:当焦点在标签1、2、3上时,按回车则触发onclick()事件 。但是如果焦点在标签W_1,W_2上按回车则不执行什么操作 你这段代码按回车将什么都不做,因为没有Form标签.想要只在层checkid中提交,可以将Form标签加在该层中(FORM标签应该包含那三个input),并且在里面加上SUBMIT标签.如:<body> <div id="checkid"><form action="" method="post"> <input type="text" id="1"size="20"/> <input type="text" id="2"size="20"/> <input type="text" id="3"size="20"/> <input type="submit" id="4"size="0" style="display:none;"/> </form> </div> <input type="text" id="W_1"size="20"/> <input type="text" id="W_2"size="20"/> <input type="button" name ="button"/> </body>这样在标签W_1,W_2上按回车则不执行什么操作 用JS写即可: <body> <div id="checkid"> <input type="text" name=text1 id="1"size="20"/> <input type="text" name=text2 id="2"size="20"/> <input type="text" name=text3 id="3"size="20"/> </div> <input type="text" id="W_1"size="20"/> <input type="text" id="W_2"size="20"/> <input type="button" name ="button"/> </body><script>var obj = document.getElementById("checkid");function document.onkeydown(){ if(window.event.keyCode==80) if(event.srcElement.parentNode==obj){ var arr = obj.childNodes; var s = "xxx.jsp?"; for(i=0;i<arr.length;i++) if(arr[i].nodeName.toLowerCase()=="input") s += arr[i].name+"="+arr[i].value+"&"; alert("going to "+s); window.location = s; }}</script> 这个是按P提交的要用ENTER请修改这里:if(window.event.keyCode==80) 你好 zapdos ,用你的这个方法好象也不行啊,有没有其他的方法呢 下班前揭贴, 解决方案:<script>function document.onkeydown(){ alert("codede"+window.event.keyCode); if(window.event.keyCode==13) try{ if(document.getElementById(document.activeElement.id).parentNode.nodeName=="DIV"){ alert("ok"); } }catch(e){} }</script> java 如何调用.net 带有dataset参数的webserver 如何在一个页面中调用webservice jsp页面中显示百分数 怎样写一个管理系统 大家谁会这个问题给我解答下,谢谢 站在JSP的晋级路口,迷惘了。 关于java正则表达式的问题 要开发一个使用MySql,MSSQL,oracle,db2通用的,JDBC作驱动的系统需要注意什么? xml的传输 调用OpenOffice服务转换PDF问题 sitemesh在weblogic下的超牛B问题,谁来解? 100分求:如何提高lucene的搜索准确度
如果有type=submit的input,则回车都会自动提交。你的代码加上form的话应该都会自动提交。
讲的不明白吗?
<body>
<div id="checkid">
<input type="text" id="1"size="20"/>
<input type="text" id="2"size="20"/>
<input type="text" id="3"size="20"/>
</div>
<input type="text" id="W_1"size="20"/>
<input type="text" id="W_2"size="20"/>
<input type="button" name ="button"/>
</body>
这样说吧,只要当焦点在<div>里面的标签上,按回车就触发onclick()事件, 反之如果不在则不做操作
如:当焦点在标签1、2、3上时,按回车则触发onclick()事件 。但是如果焦点在标签W_1,W_2上按回车则不执行什么操作
<body>
<div id="checkid">
<form action="" method="post">
<input type="text" id="1"size="20"/>
<input type="text" id="2"size="20"/>
<input type="text" id="3"size="20"/>
<input type="submit" id="4"size="0" style="display:none;"/>
</form>
</div>
<input type="text" id="W_1"size="20"/>
<input type="text" id="W_2"size="20"/>
<input type="button" name ="button"/>
</body>
这样在标签W_1,W_2上按回车则不执行什么操作
<div id="checkid">
<input type="text" name=text1 id="1"size="20"/>
<input type="text" name=text2 id="2"size="20"/>
<input type="text" name=text3 id="3"size="20"/>
</div>
<input type="text" id="W_1"size="20"/>
<input type="text" id="W_2"size="20"/>
<input type="button" name ="button"/>
</body><script>
var obj = document.getElementById("checkid");
function document.onkeydown(){
if(window.event.keyCode==80)
if(event.srcElement.parentNode==obj){
var arr = obj.childNodes;
var s = "xxx.jsp?";
for(i=0;i<arr.length;i++)
if(arr[i].nodeName.toLowerCase()=="input")
s += arr[i].name+"="+arr[i].value+"&";
alert("going to "+s);
window.location = s;
}
}
</script>
要用ENTER请修改这里:
if(window.event.keyCode==80)
function document.onkeydown(){
alert("codede"+window.event.keyCode);
if(window.event.keyCode==13)
try{
if(document.getElementById(document.activeElement.id).parentNode.nodeName=="DIV"){
alert("ok");
}
}catch(e){}
}
</script>