【问题标题】:Enter key to move between form fields with submit button输入键在带有提交按钮的表单域之间移动
【发布时间】: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 此代码在没有提交按钮的情况下工作。它不能与提交按钮一起使用我应该做什么更改

标签: html css


【解决方案1】:

添加 onclick="return false;"在提交按钮的输入标签中,然后输入将引导您进入下一个控件。

<input style="margin:20px 20px 20px 250px;" type="submit" name="Submit" onclick="return false;" value="Submit"/>

【讨论】:

  • 如果我使用这个 -- onclick="return false;"该页面不会重定向到下一页
  • 在它之前添加一些函数调用并在那里解密你的功能。
猜你喜欢
  • 2013-08-21
  • 2011-01-26
  • 2014-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-14
相关资源
最近更新 更多