我正在開發一個網站,其中我會做一個刪除按鈕的序列,我的意思是隻有一個按鈕刪除兩個輸入字段,這是可能的做jQuery?刪除按鈕序列與jquery
這裏是我的HTML代碼:
a: <input type="text" maxlength="5" id="username" />
c: <input type="text" maxlength="5" id="password" />
<button type="button" class="delete">
Delete
</button>
這裏是我的jQuery代碼:
$("input").bind("input", function() {
var $this = $(this);
setTimeout(function() {
if ($this.val().length >= parseInt($this.attr("maxlength"),10))
$this.next("input").focus();
},0);
});
$('#password').on('input', function(){
if($(this).val() == ''){
$('#username').focus();
return false;
}
});
$(document).on('click', '.delete', function(e){
if($('#password').val == '') {
var $content = $('#username');
} else if ($('#password').val !== '') {
var $content = $('#password');
}
var html = $content.val();
$content.val(html.substr(0, html.length - 1));
if($content.val() == '') {
$('#username').focus();
} else if ($content.val() !== '') {
$content.focus();
}
return false;
});
我已經嘗試過自己,但都沒有成功!
單擊「刪除」按鈕時,您想要執行什麼操作? –
@PraneshRavi清除輸入字段。 –
是的夥計,當「刪除」按鈕點擊@PraneshRavi –