私はjqueryに少し慣れていないので、ご容赦ください。
私は登録システムに取り組んでおり、パスワードとパスワードの確認テキスト ボックスがあります。2 つのボックスの内容が変わるたびに、確認ボックスの背景色を設定したいと思います。ボックスの内容が一致するかどうかに基づいて色が決まります。
編集 - 元のコードは背景色をまったく変更していませんでした。フォーカス/ぼかしではなく、ユーザーのタイプに合わせて変更したいと思います。
私のコードは次のとおりです。
<input type="password" name="password" id="newpassword"/>
<input type = "password" name = "confirm" id="confirm"/>
<input type="submit" value="Register" id="Register"/>
<script>
$(document).ready(function () {
$('#password').change(function () {
if ($('#newpassword').val().Equals($('#confirm').val())) {
$('#confirm').attr("backgroundcolor", "green");
$('#Register').attr("disabled", "");
} else {
$('#confirm').attr("backgroundcolor", "red");
$('#Register').attr("disabled", "disabled");
}
});
$('#confirm').change(function () {
if ($('#newpassword').val().Equals($('#confirm').val())) {
$('#confirm').attr("backgroundcolor", "green");
$('#Register').attr("disabled", "");
} else {
$('#confirm').attr("backgroundcolor", "red");
$('#Register').attr("disabled", "disabled");
}
})
</script>
前もって感謝します