【发布时间】:2014-02-20 18:06:52
【问题描述】:
Enter 键可在带有提交按钮的表单字段之间移动。 我尝试了这段代码,但它不起作用。 此代码是使用输入键在表单字段之间移动: 它在没有提交按钮的情况下工作我应该做些什么朋友请帮助我
<Script Language=JavaScript>
function toEOT(isField){
isRange = isField.createTextRange();
isRange.move('textedit');
isRange.select();
}
function actTab(isField){
if (event.keyCode == 13)
{
nextField = isField.tabIndex;
nextField++;
if (nextField < document.forms.Form1.length)
{document.forms.Form1[nextField].focus()}
else {document.forms.Form1[0].focus()}
}
}
function init(){
document.forms.Form1[0].focus();
}
event.preventDefault();
window.onload=init;
</Script><br>
</Head>
<Body>
<Form name='Form1'>
<fieldset>
<legend>Fills</legend>
<input type=text value="This is Some Text" size=25 onFocus="toEOT(this)" onKeyUp="actTab(this)" tabindex='1'><br>
<input type=text value="Some Text" size=25 onFocus="toEOT(this)" onKeyUp="actTab(this)" tabindex='2'><br>
<input type=text value="Nothing" size=25 onFocus="toEOT(this)" onKeyUp="actTab(this)" tabindex='3'><br>
<input type=text value="Two Words" size=25 onFocus="toEOT(this)" onKeyUp="actTab(this)" tabindex='4'><br>
<select >
<option>geetha</option>
<option>geetha</option>
<option>geetha</option>
</select>
<select >
<option>geetha</option>
<option>geetha</option>
<option>geetha</option>
</select>
<input type=text value="Two Words" size=25 /><br>
<input style="margin:20px 20px 20px 250px;" type="submit" name="Submit" value="Submit"/>
</fieldset>
</Form>
【问题讨论】:
-
要在字段之间移动,您不应尝试使用
enter键。因为它的默认行为是提交表单。因此,只需对每个字段使用 TAB 序列即可。 -
您的代码需要传递事件并在除 ie 之外的所有其他浏览器中进行测试
-
@mplungjan 此代码在没有提交按钮的情况下工作。它不能与提交按钮一起使用我应该做什么更改