我试图这样做,以便当我在textarea框中输入内容时,我的textarea框变为黑色,而我的包含该框标题的div也变为黑色。但如果没有输入任何内容或输入内容,则擦除这些项目将保持灰色。正如你所看到的,我没有试图解决实际上textarea盒子变黑的问题。感谢
我的jQuery
$( '#message_input' )
.click( function () {
var text = $( this ).val;
if(text == 'add additional information here!') {
$('#message_title').css('color','#666');
} else {
$('#message_title').css('color','#000');
}
});
我的HTML
<div id="message_title">Message</div>
<textarea name="message" id="message_input" rows="4" cols="21" maxlength="200"
onfocus="if(this.value=='Add additional information here!')
{this.value='';this.style.color='#000';}"
onblur="if(this.value=='') {
this.value='Add additional information about the fruit here!';this.style.color='#999';}"
>Add additional information here!</textarea>