【问题标题】:Can't change text after set readOnly=false IE设置 readOnly=false IE 后无法更改文本
【发布时间】:2014-10-16 20:55:56
【问题描述】:

我有这个示例代码,它不能只在 IE 中工作。有没有 IE 漏洞?

<input type="text" readonly="true" onclick="setReadonlyfalse(this)" />

<script type="text/javascript">
    function setReadonlyfalse(ed){
        ed.readOnly = false;
    }
</script>

我正在模拟一种情况,在我的网格显示编辑器后,我收到来自服务器的响应,将我的编辑器设置为 readonly=false。 (它是用 readonly=true 渲染的)

编辑:

我使用的是 ExtJS 3.4,代码是这样做的:

/**
 * Sets the read only state of this field.
 * @param {Boolean} readOnly Whether the field should be read only.
 */
setReadOnly : function(readOnly){
    if(this.rendered){
        this.el.dom.readOnly = readOnly;
    }
    this.readOnly = readOnly;
}

edit2: 我将代码调整为更正确

<input type="text" readonly="readonly" onclick="removeReadonly(this)" value="hehehe" />
<script type="text/javascript">
    function removeReadonly(ed){
        ed.removeAttribute("readonly");
    }
</script>

【问题讨论】:

  • 如果这个编辑器失去焦点并再次获得焦点,它会工作......
  • 您需要删除属性而不是设置它为假。检查此链接:stackoverflow.com/questions/16298281/…
  • 我正在使用 ExtJS,它们的代码设置为 false。但是,如果删除而不是设置为 false 是正确的,我会做一个解决方法。谢谢
  • @Omidam81 请注意,该问题的答案仅显示了 jQuery 方式 (.prop()) 执行 ed.readOnly = false;
  • readonly 是一个布尔属性——在您的 HTML 中,您可以使用readonly="readonly"readonly,但不能使用readonly="true"w3 validator 表示“元素输入上只读属性的错误值为 true。”

标签: javascript html internet-explorer input readonly


【解决方案1】:

以编程方式从元素中删除readonly 属性,然后将readOnly 设置为false

ed.removeAttribute('readonly'); // only needed the first time
ed.readOnly = false;

是的,这是一个 IE 错误。

【讨论】:

  • 你知道是否有漏洞打开或在某处描述过吗?我搜了没找到。
  • @patricK:由于readOnly 可以在所有其他浏览器中运行并且根据标准,我得出结论认为 IE 是错误的。但我本身没有证据。这行得通吗?
  • 不幸的是,IE 没有任何改变,但我认为这是一个错误并决定在服务器端进行修复(在这种情况下未设置为只读)谢谢
猜你喜欢
  • 2016-05-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-24
  • 2015-02-12
  • 2020-04-04
相关资源
最近更新 更多