【发布时间】: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