我正在尝试更改value元素上的<textarea>。此代码在Firefox中运行良好,但IE声称存在错误onblur并且未设置该值。

<textarea 
    name="comment" 
    id="comment" 
    rows="8" 
    cols="80"
    style="color:grey;" 
    onfocus="if(this.value=='Add a comment...') {this.style.color='black'; this.value='';}"
    onblur="if(this.value=='') {this.style.color='grey'; this.value='Add a comment...';}">Add a comment...</textarea>

我做错了什么?

有帮助吗?

解决方案

这会导致问题吗?

  

this.style.color = '灰色'

this.style.color='gray';

整个代码:

<textarea name="comment" id="comment" rows="8" cols="80" style="color: gray;" onfocus="if(this.value=='Add a comment...') {this.style.color='black'; this.value='';}"
        onblur="if(this.value=='') {this.style.color='gray'; this.value='Add a comment...';}">Add a comment...</textarea>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top