2014-01-29 95 views
0

用提交按鈕輸入表單字段間的移動鍵。 我試過這段代碼,但它不工作。 此代碼是用輸入表單字段之間移動鍵: 它的工作沒有提交按鈕我應該做怎樣的變化朋友請幫我用提交按鈕輸入表單字段間的移動

<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> 
+1

要在字段間移動,您不應該嘗試使用「輸入」鍵。因爲它的默認行爲是提交表單。所以只需使用TAB序列爲每個字段。 – Parixit

+0

您的代碼需要通過事件並在所有其他瀏覽器中進行測試,比如 – mplungjan

+0

@mplungjan此代碼無需提交按鈕即可使用。它不與提交按鈕一起工作我應該做些什麼 – user2978559

回答

1

添加的onclick =「返回false;」在提交按鈕的輸入標籤中,然後輸入wil將引導您到下一個控件。

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

if if this use - onclick =「return false;」該頁面將不會重定向到下一頁 – user2978559

+0

在它之前添加一些函數調用並在那裏解析你的功能。 – Learner