我有2个字段的旧密码和新密码。在旧的密码字段中,我提供已保存在数据库中的旧密码。如果它不正确,则会发出警报消息,但该警报在提供后仍未删除正确的密码。我在模糊函数中给出了这个
答案 0 :(得分:0)
您必须提供必要的代码。但这样做的一般方法如下:
var oldpass = '1234',
old = document.getElementById( 'oldPass' );
old.addEventListener( 'blur', function () {
if ( this.value && this.value != oldpass ) {
alert( 'Password don\'t Match!' )
} else {
document.getElementById( 'newPass' ).removeAttribute( 'disabled' );
document.getElementById( 'newPass' ).focus()
}
} )

<p>Old Password is: <b>1234</b></p>
<input type="text" id="oldPass" placeholder="Enter old password" />
<br>
<input type="text" id="newPass" placeholder="Enter a new password" disabled />
&#13;
或者,当用户输入密码时,您可以这样做:
var oldpass = '1234',
old = document.getElementById( 'oldPass' );
old.addEventListener( 'input', function () {
if ( this.value != oldpass ) {
this.style.backgroundColor = 'red'
} else {
this.style.backgroundColor = 'green';
document.getElementById( 'newPass' ).removeAttribute( 'disabled' );
document.getElementById( 'newPass' ).focus()
}
} )
&#13;
<p>Old Password is: <b>1234</b></p>
<input type="text" id="oldPass" placeholder="Enter old password" />
<br>
<input type="text" id="newPass" placeholder="Enter a new password" disabled />
&#13;