我正在嘗試確定工作流以微調數據錄入Web應用程序。想象幾個地址形式單一的網頁上:jQuery交出焦點並點擊元素
1. Name___________
Street_________
Phone__________
2. Name___________
Street_________
Phone__________
[...many more...]
現在我想知道,如果用戶使用Tab鍵進入第二個「名稱」字段(或記錄內的任何地方),或如果他們使用鼠標點擊它。 (或者Shift-Tab鍵反向移動。)
我給自己定一個處理器上的兩個重點,點擊輸入字段:
$('input').click(function() { TabulateClick(this) });
$('input').focus(function() { TabulateFocus(this) });
並在處理程序,我確定解決用戶工作,以及我們是否「轉換」地址記錄。 (如果焦點在「手機」爲第一地址,並且您在同一地址點擊「名稱」字段,這不是實際切換的記錄,所以我不製表這一點。)
function TabulateClick(field)
{
var currentAddressRecord = FindAddress(field);
if (lastAddressRecord != currentAddressRecord)
switchedAddressesWithClick++;
lastAddressRecord = currentAddress;
}
function TabulateFocus(field)
{
var currentAddress = FindAddress(field);
if (lastAddressRecord != currentAddressRecord)
switchedAddressesWithTab++;
lastAddressRecord = currentAddress;
}
我的問題是,當我用鼠標點擊該字段時,focus
事件首先觸發了一個虛假的switchedAddressesWithTab
並更改currentAddress(即差)。當click
處理程序運行時,lastAddressRecord
變壞。
focus
處理程序中是否有一種方法知道在同一個對象上有一個待處理的click
事件?或者在click
處理程序中知道它以前只由focus
處理?
嗯,非常有趣,這是測試? – 2011-02-03 17:22:48
@Josiah:我不認爲這是有效的 - 在FF中,即使我選中該字段,我也不明確。 – 2011-02-03 17:24:45