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