我对jquery有点新,所以请耐心等待。文字元素背景颜色变化
我正在开发注册系统并有密码并确认密码文本框。我希望设置确认框的背景颜色,只要两个框的内容发生变化。颜色将基于箱子内容是否匹配。
编辑 - 我原来的代码根本不改变背景颜色。我希望在用户输入时改变它,而不是焦点/模糊。
我的代码如下。
<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>
在此先感谢
而且?什么不起作用?错误信息 ? – Virus721
你面临什么问题 –
你在最后留下了'});'。 – Neal