2010-08-30 17 views
1

我想單獨的DIV持有的輸入也改變背景顏色。我如何將它添加到我的現有代碼中?添加元素以改變現有的onblur

<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> 

回答

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> 
+0

我試了,只有輸入的變化。這裏是我的html:

Erik 2010-08-30 19:26:55

+0

@Erik Moin的代碼看起來正確。你有爲''div id =「quote_input」>'定義的'highlight'類嗎? – Pat 2010-08-30 19:30:46

+0

感謝Moin ...你的幫助做到了。我發現了一個錯字。非常感謝。 – Erik 2010-08-30 19:30:46

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

相關問題