2011-11-07 81 views
0

我有一個表單,我在其中使用4個文本框。標籤按鈕不在表單文本字段中工作

textfield1的 文字欄 文字欄 文字欄

我呼籲文字欄和文字欄上的「onpress」事件功能只檢查整數值。該功能在下面給出。

function checkIntnumber(obj,event){ 
var unicode=event.charCode? event.charCode : event.keyCode 
if((unicode==37 || unicode==39 || unicode==35 || unicode==36 || unicode==46) 
    && event.which==0) {//if the key isn't the (BackSpace/Left Arrow/Right 
    Arrow/Delete/Home/End) key (which we should allow) 
     return true; 
} else if(unicode!=8) { 
     if (unicode>=48 && unicode<=57) { //if a number 
      return true; //enable key press 
     } else { 
      return false; //disable key press 
     } 
} 
} 

現在的話,我從textfield1的移動使用TAB鍵,這是工作正常,但tab鍵不能正常工作,從文本字段2到文字欄或文字欄移動到文字欄以文字欄。這個問題只發生在Mozilla Firefox中。請幫幫我。 感謝

編輯:從答案下方留言代碼 -

<input type="text" name="from" id="from" style="width:50px;" 
     onkeypress="hideRateDiv();return checkIntnumber(this,event)"/> 
- <input type="text" name="to" id="to" style="width:50px;" 
     onkeypress="hideRateDiv();return checkIntnumber(this,event)" tabindex="2"/> 
+0

聽起來更像是tabindex屬性,而不是事件綁定一個問題... –

+0

那麼我應該怎麼做呢? – manishjangir

+0

http://www.w3.org/TR/html4/interact/forms.html#adef-tabindex檢查此鏈接 –

回答

0

你只需要測試對應於tab鍵(9)的代碼,並返回true。

編輯:對不起,剛剛看到Christian的評論,並更仔細地讀了一下這個問題。可能存在tabindex問題,但是如果在源HTML中四個字段緊跟在一起,那麼不應該有這個問題。但鑑於你發佈的代碼似乎不允許Tab鍵,我不明白你的字段1和2之間的tab鍵會如何工作 - 它們之間不應該有效。

您可以請發佈這些字段的HTML並顯示您如何分配按鍵事件?

+0

- manishjangir

+0

任何人都可以告訴我確切的問題。 – manishjangir

0

if((unicode==37 || unicode==39 || unicode==35 || unicode==36 || unicode==46 || unicode==9) && event.which==0)更改,如果條件就是這樣,鍵代碼標籤也(即9)