1

我想要一个单独的 DIV 来保存输入以改变背景颜色。我如何将它添加到我现有的有效代码中?

<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("input:[type=text]").focus(function () {
 jQuery(this).addClass("highLightInput");

});
jQuery("input:[type=text]").blur(function () {
jQuery(this).removeClass("highLightInput");
});
    });
 </script>
4

2 回答 2

2
<script type="text/javascript">
$(document).ready(function() {
$("input:[type=text]").focus(function () {
 $(this).addClass("highLightInput");
$(this).parent('div').addClass('highlight');

});
$("input:[type=text]").blur(function () {
$(this).removeClass("highLightInput");
$(this).parent('div').removeClass('highlight');
});
    });
 </script>
于 2010-08-30T19:24:43.353 回答
0

停止使用 JavaScript 来解决可以用 CSS 解决的问题。唯一的限制是它不支持 IE6/7

textarea.yourClass {
    width: 100%; 
    background: white url('iamges/img.png') no-repeat 50% 50%; 
    color: grey;
}
textarea.yourClass:focus {
    color: #444; 
    background: none;
}

如果你确实需要支持 IE6/7,那么使用上面的 JS 方法

于 2013-04-05T06:52:10.630 回答