Text input readonly attribute not recognized in IE7?

自古美人都是妖i 提交于 2019-12-05 11:20:27

Did you try this?

document.getElementById("my_id").readOnly = true;

try:

document.getElementById("my_Id").setAttribute("readOnly","readonly")

it is readOnly, O is capital!

<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. This should work from IE7 to IE11.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!