<script type="text/javascript">
function ClearSubmit(e) {
e = e ? e : window.event;
var keyCode = e.which ? e.which : e.keyCode;
if (event.keyCode == 13) {
e.keyCode = 9
e.returnValue = false;
document.getElementById('TextBox2').focus();
}
}
</script>
调用代码:
<input id="Text1" type="text" name="TextBox1" onkeydown="return ClearSubmit(event)"/><input id="Text2" type="text" name="TextBox2" />
<input id="Submit1" type="submit" value="submit" />
谁能帮我看看哪里写错了?
3 个解决方案
#1
function ClearSubmit(e) {
e = e ? e : window.event;
var keyCode = e.which ? e.which : e.keyCode;
//if (event.keyCode == 13) {
if (keyCode == 13) {
document.getElementById('TextBox2').focus();
return false;
}
}
<input id=" TextBox2" type="text" name="TextBox2" />
#2
chrome中测试,没问题
#3
<script type="text/javascript">
function ClearSubmit(e) {
e = e ? e : window.event;
var keyCode = e.which ? e.which : e.keyCode;
if (e.keyCode == 13) {
alert("a");
document.getElementById('TextBox2').focus();
e.keyCode = 9
e.returnValue = false;
}
}
</script>
</head>
<body>
<input id="Text1" type="text" name="TextBox1" onkeydown="return ClearSubmit(event)"/>
<input type="text" name="TextBox2" id="TextBox2" />
<input id="Submit1" type="submit" value="submit" />
</body>
第二个文本框的id貌似和document.getElementById里的id不相同啊
event.keyCode == 13也不对啊 貌似
function ClearSubmit(e) {
e = e ? e : window.event;
var keyCode = e.which ? e.which : e.keyCode;
if (e.keyCode == 13) {
alert("a");
document.getElementById('TextBox2').focus();
e.keyCode = 9
e.returnValue = false;
}
}
</script>
</head>
<body>
<input id="Text1" type="text" name="TextBox1" onkeydown="return ClearSubmit(event)"/>
<input type="text" name="TextBox2" id="TextBox2" />
<input id="Submit1" type="submit" value="submit" />
</body>
第二个文本框的id貌似和document.getElementById里的id不相同啊
event.keyCode == 13也不对啊 貌似
#1
function ClearSubmit(e) {
e = e ? e : window.event;
var keyCode = e.which ? e.which : e.keyCode;
//if (event.keyCode == 13) {
if (keyCode == 13) {
document.getElementById('TextBox2').focus();
return false;
}
}
<input id=" TextBox2" type="text" name="TextBox2" />
#2
chrome中测试,没问题
#3
<script type="text/javascript">
function ClearSubmit(e) {
e = e ? e : window.event;
var keyCode = e.which ? e.which : e.keyCode;
if (e.keyCode == 13) {
alert("a");
document.getElementById('TextBox2').focus();
e.keyCode = 9
e.returnValue = false;
}
}
</script>
</head>
<body>
<input id="Text1" type="text" name="TextBox1" onkeydown="return ClearSubmit(event)"/>
<input type="text" name="TextBox2" id="TextBox2" />
<input id="Submit1" type="submit" value="submit" />
</body>
第二个文本框的id貌似和document.getElementById里的id不相同啊
event.keyCode == 13也不对啊 貌似
function ClearSubmit(e) {
e = e ? e : window.event;
var keyCode = e.which ? e.which : e.keyCode;
if (e.keyCode == 13) {
alert("a");
document.getElementById('TextBox2').focus();
e.keyCode = 9
e.returnValue = false;
}
}
</script>
</head>
<body>
<input id="Text1" type="text" name="TextBox1" onkeydown="return ClearSubmit(event)"/>
<input type="text" name="TextBox2" id="TextBox2" />
<input id="Submit1" type="submit" value="submit" />
</body>
第二个文本框的id貌似和document.getElementById里的id不相同啊
event.keyCode == 13也不对啊 貌似