gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 03:19:10 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com