試試這個:http://jsfiddle.net/aaK9E/51/
var showPass = false;
$('#c').attr('disabled', 'disabled'); // disabled on doc ready
$('#c').change(function() {
showPass = ($('#c:checked').length > 0);
if (showPass) {
$('#p').hide();
$('#t').show();
} else {
$('#t').hide();
$('#p').show();
}
});
$('#p').keypress(function() { // use keypress instead of change
$('#c').removeAttr('disabled'); // remove the attr 'disabled'
if (!showPass) $('#t').val($('#p').val());
});
$('#t').change(function() {
if (showPass) $('#p').val($('#t').val());
});
你可以改變這個如果backspace is done
和密碼字段不具有任何價值:
$('#p').keyup(function() {
$('#c').removeAttr('disabled');
if (!showPass) {
$('#t').val($('#p').val());
}
if ($(this).val() == '') { // this will check the val if there is not
$('#c').attr('disabled', 'disabled'); it will disable it again.
}
});
如果鱸jQuery是使用:
$('#p').on('keyup', function() { // this '.on()' requires latest jquery
$('#c').removeAttr('disabled');
if (!showPass) {
$('#t').val($('#p').val());
}
if ($(this).val() == '') { // this will check the val if there is not
$('#c').attr('disabled', 'disabled'); it will disable it again.
}
});
如果需要try to use latest jquery
來源
2013-01-10 16:50:01
Jai
之後我刪除所有字符,並集中了,它使複選框啓用 – 3zzy
PLZ看到更新後的小提琴http://jsfiddle.net/aaK9E/51/。並回答更新。 – Jai