我想当我改变#town
和#animal
的值,那么输入背景就会变红。 我的代码是改变输入背景,当我改变一个输入,但我想,如果我改变这两个输入,代码后将改变背景颜色。jQuery改变方法多个元素
我的代码:
<!DOCTYPE html>
<html>
<head>
<title>Test page</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('#town, #animal').on('change', function() {
$('input').css('background', 'red');
});
});
</script>
</head>
<body>
<input type="text" id="town">
<input type="text" id="animal">
</body>
</html>
“您想将文本输入颜色更改为红色onChange”我收到了您的问题的第一部分,我认为。第二部分更难阅读。也许你只是想改变颜色,如果两个输入都改变了? – Dominik