[英]Text input readonly attribute not recognized in IE7?
I am setting readonly="readonly" (in other words, true) via javascript: 我通过javascript设置readonly =“readonly”(换句话说,是真的):
document.getElementById("my_id").setAttribute("readonly", "readonly");
This is having the intended effect (making the field no longer editable, but its contents are submitted with the form) in FF, Safari and Chrome, but not for IE7. 这在FF,Safari和Chrome中具有预期效果(使字段不再可编辑,但其内容随表单一起提交),但不适用于IE7。 In IE7 I can still modify the contents of the text input field.
在IE7中,我仍然可以修改文本输入字段的内容。
I have tried setting ("readonly", "true") as well, which works in all three other browsers that I am testing, but which IE7 also ignores. 我也尝试过设置(“readonly”,“true”),它适用于我正在测试的所有其他三个浏览器,但IE7也忽略了这些浏览器。
Does anyone have experience with trying to do this with IE7? 有没有人有尝试用IE7做这个的经验? I do not want to use the disabled attribute as I want the value within the text input field to be submitted with the form.
我不想使用disabled属性,因为我希望文本输入字段中的值与表单一起提交。
你试过这个吗?
document.getElementById("my_id").readOnly = true;
try: 尝试:
document.getElementById("my_Id").setAttribute("readOnly","readonly")
it is readOnly , O is capital! 它是只读 , O是资本!
<script type="text/javascript">
function blah(txt) {
var text = document.getElementById(txt).value;
if(text.length > 4 && document.getElementById('chk').checked == false) {
// ********* NOT WORKING WITH IE *************** //
//document.getElementById("ta").setAttribute('readOnly','readonly');
//document.getElementById("ta").readOnly="readOnly";
// ******** --- **********//
//document.getElementById("ta").disabled = true; // for disable textArea
document.getElementById("ta").blur(); // comment this when above line is uncommented or visa-versa
document.getElementById('chkBox').style.display = "block";
}
}
function unable() {
// document.getElementById("ta").disabled = false; // to unable textArea -- uncomment when disabling is used or visa-versa
document.getElementById('ta').focus();
document.getElementById('chkBox').style.display = "none";
}
</script>
<textarea id="ta" onkeydown="blah('ta')" ></textarea>
<div id="chkBox" style="display:none"><label> Please check this to continue....</label><input type="checkbox" id="chk" onclick="unable()"></div>
Or try: 或尝试:
document.getElementById("my_id").setAttribute("readOnly", true);
Please note as stated by @TheVillageIdiot, the O in readOnly is UPPER CASE . 请注意,如@TheVillageIdiot所述,readOnly中的O是大写的 。 This should work from IE7 to IE11.
这应该从IE7到IE11。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.