IE不让我用javascript设置textarea值

时间:2022-11-12 15:53:39

I'm trying to change the value on a <textarea> element. This code works great in Firefox, but IE claims there's an error onblur and doesn't set the value.

我正在尝试更改

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

What am I doing wrong?

我究竟做错了什么?

1 个解决方案

#1


Can this be causing the problem -

这可能导致问题 -

this.style.color='grey'

?

this.style.color='gray';

Whole Code:

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

#1


Can this be causing the problem -

这可能导致问题 -

this.style.color='grey'

?

this.style.color='gray';

Whole Code:

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