【问题标题】:IE not letting me set a textarea value with javascriptIE 不允许我使用 javascript 设置 textarea 值
【发布时间】:2010-10-22 20:19:21
【问题描述】:

我正在尝试更改 <textarea> 元素上的 value。此代码在 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>

我做错了什么?

【问题讨论】:

    标签: javascript html internet-explorer dom textarea


    【解决方案1】:

    这是否会导致问题 -

    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>
    

    【讨论】:

    • 很可能,它们是美国颜色名称;)
    • 是的 - 它的美国颜色名称:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-20
    • 2022-11-18
    • 2012-11-11
    • 2021-02-05
    • 1970-01-01
    • 2018-04-03
    • 1970-01-01
    相关资源
    最近更新 更多