IE不让我用javascript设置textarea值

时间:2009-04-30 12:53:32

标签: javascript html internet-explorer dom textarea

我正在尝试更改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>

我做错了什么?

1 个答案:

答案 0 :(得分:2)

这会导致问题吗?

  

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>