2012-10-22 13 views
0

我有這樣的小提琴,當我按下選項卡上,重點應下一個元素集,但它不是.. 下面的代碼..jQuery的警報重置重點不同的元素?

<input type="text" style="font-size:12px;width:245px;" border-style="Solid" tabindex="3" id="txtCAddress" maxlength="100" name="txtCAddress" /> 
</br> 

<input type="text" style="font-size:12px;width:245px;" border-style="Solid" tabindex="4" id="txtMobile" name="txtMobile"/> 

</br> 

<input type="text" style="font-size:12px;width:245px;" border-style="Solid" id="txtPriority" maxlength="300" name="txtPriority" tabindex="5" autocomplete="off" /> 

JS的是

$(document).ready(function(event) { 
    $('#txtCAddress').keydown(function(e) { 
     if ((e.which == 9)) { 
      if ($('#txtCAddress').val() == '') { 
       alert('me'); 
      } 
     } 
    }); 
}); 

當我按txtCAddress中的標籤並附上一些文字,但沒關係,關注的是txtMobile的設置除外,但是當我按下txtCAddress中的標籤時沒有任何文字時,警報即將到來,但是關注點已經設置在txtPriority

爲什麼重點不在txtMobile

編輯 JS的小提琴

http://jsfiddle.net/sXaMG/1/

+0

對於我來說,這不是發生在小提琴上 - txtMobile在關閉警報後獲得焦點。我只在IE9中測試過。 –

+0

@AlanShortis。與鉻一樣。 – gdoron

+0

@gdoron。與Firefox相同。加工。 – Rac

回答

0

你不應該使用alert()中的keydown回調函數作爲其覆蓋事件的默認行爲,使用的console.log()來代替。從此,似乎完美地工作。

+0

那麼,它爲什麼在IE 8,IE9,opera中工作?和safari?而只是不是Firefox? – Razort4x