我想让 div 背景颜色只有在输入字段中有文本并且没有文本时颜色不会改变或恢复为原始颜色时才会改变颜色。到目前为止,这是我的代码,但它不起作用。
<script type="text/javascript">
$(document).ready(function () {
$('#inputDatabaseName').change(function () {
$(this).parent().find('#colorchange').css('background-color','#ff0000');
$(this).css('background-color','#ff0000');
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="colorchange">
<input id="inputDatabaseName">
<table id="searchResults"><tr><td>empty</td></tr></table>
</div>
</form>
</body>