2009-11-30 47 views
0

我正在使用jQuery複製iPhone解鎖屏幕。我在實現自動標籤和刪除密碼解鎖頁面時遇到了麻煩。使用jQuery自動標籤和刪除按鈕

另外,我怎麼能實現一個刪除按鈕,它自動反向清除輸入字段?

$("#keypad li a.delete").click(function() { 
    $("input.focus").val("").removeClass("focus").prev().addClass("focus").focus(); 
}); 

我的本意是,最後填充輸入有一類focus,因此刪除按鈕會從那裏開始攜手其返回途中,當它運行的輸入停止。

刪除按鈕根本不會做任何事情時單擊。我該如何解決這個問題?

回答

0

要查看當前元素的索引可以使用

if($(this).prevAll("input").size() < 3){...} 

和你的「刪除按鈕」功能看起來沒給我,所以也許你要闡述你用它遇到的問題?

+0

的刪除和取消按鈕都是一樣的,當我有'取消()'功能啓用它會覆蓋任何刪除按鈕功能。 – peehskcalba 2009-11-30 20:37:18

1

這個腳本解決所有問題,

$("#pw-container form input").keyup(function() { 
    if ($("#pw-container form input:first").val().length > 0) { 
     $("#keypad li a.cancel").removeClass("cancel").addClass("delete").text("Delete"); 
     if($(this).prevAll("input").size() === 3) { 
      $(this).addClass("focus").focus(); 
     } else if ($(this).val().length > 0) { 
      $(this).removeClass("focus").next().addClass("focus").focus(); 
     } 
    } else if ($("#pw-container form input:first").val().length === 0) { 
     $("#keypad li a.delete").removeClass("delete").addClass("cancel").text("Cancel"); 
    } 
}); 

此外,HTML,

<input type="password" maxlength="1" size="1" class="focus" /> 
<input type="password" maxlength="1" size="1" /> 
<input type="password" maxlength="1" size="1" /> 
<input type="password" maxlength="1" size="1" />