我遇到了 onkeydown 事件的问题。我在 2 个输入元素上使用它,但它只适用于第一个。第二,它只是给了我错误:Uncaught TypeError: object is not a function
.
jQuery:
function count() {
var length = $('#pass').length;
if (length < 32) {
$('#length').text(length + ' characters out of 32');
}
}
function match() {
if ($('#pass').attr('value') == $('#pass2').attr('value'))
{
$('#match').text('<img src="/css/images/check.png" /> Passwords match.');
}
else
{
$('#match').text('<img src="/css/images/close.png" /> Passwords do not match.');
}
}
HTML:
<form method='post'>
<input type='password' name='pass' value='' id='pass' onkeydown='count()' />
<span id='length'></span>
<input type='password' name='pass2' value='' id='pass2' onkeydown='match()' />
<span id='match'></span>
</form>