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

标签 javascript html internet-explorer input readonly

我有这个示例代码,它不能只在 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;
}

编辑2: 我把代码调整得更正确了

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

最佳答案

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

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

是的,这是一个 IE 错误。

关于javascript - 设置 readOnly=false IE 后无法更改文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25456578/

相关文章:

javascript - 简单的 JavaScript 浏览器检查器

html - 复选框黑客语法的困难

php - jQuery 浏览器兼容性 (IE)

javascript - 更改 <img src ="XXX"/>,新图像完成加载时的 js 事件?

javascript - 给每个元素一个唯一的ID

javascript - 用 3 个按钮制作一个程序。文本输入将输出前的大小写改成p。如何进行?

javascript - HTML5 是否允许拖放上传文件夹或文件夹树?

asp.net - 兼容性问题是IE10

flash - 如何从javascript调用IE中动态创建的flash外部接口(interface)?

javascript - 淡化动态更改的 (jQuery) 背景图像?