简体   繁体   English

设置readOnly = false IE后无法更改文本

[英]Can't change text after set readOnly=false IE

I have this sample code, and It's not working just in IE. 我有此示例代码,并且它不能仅在IE中工作。 Is there an IE bug? 是否有IE错误?

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

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

I'm simulating a situation that after my grid show an editor, I receive a response from server to set my editor to readonly=false. 我正在模拟一种情况,在网格显示编辑器后,我收到服务器的响应,将编辑器设置为readonly = false。 (it was rendered with readonly=true) (它使用readonly = true呈现)

edit: 编辑:

I'm using ExtJS 3.4, and the code do this: 我正在使用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 : I'm adjusted the code to be more correct edit2 :我调整了代码,使其更正确

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

Remove the readonly attribute from the element programmatically, then set readOnly to false . 以编程方式从元素中移除readonly属性,然后将readOnly设置为false

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

Yes, this is an IE bug. 是的,这是一个IE错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM