我只想在輸入字段中存在文本時沒有文本,並且顏色沒有改變或者它恢復爲原始的顏色。這是我的代碼到目前爲止,它不起作用。在字段中輸入文本改變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>
您的JS甚至不似乎是有效的做到這一點。試試jsfiddle.net(jshint) – pmandell
長話短說,你關閉了你的改變功能,但沒有你的就緒功能。修復並再試一次。並且在將來,請檢查您的錯誤控制檯。 – 2013-08-01 19:24:03