'innerText' works in IE, but not in Firefox

前端 未结 15 1463
执念已碎
执念已碎 2020-11-21 05:01

I have some JavaScript code that works in IE containing the following:

myElement.innerText = \"foo\";

However, it seems that the \'innerTex

15条回答
  •  情深已故
    2020-11-21 05:39

    This has been my experience with innerText, textContent, innerHTML, and value:

    // elem.innerText = changeVal;  // works on ie but not on ff or ch
    // elem.setAttribute("innerText", changeVal); // works on ie but not ff or ch
    // elem.textContent = changeVal;  // works on ie but not ff or ch
    // elem.setAttribute("textContent", changeVal);  // does not work on ie ff or ch
    // elem.innerHTML = changeVal;  // ie causes error - doesn't work in ff or ch
    // elem.setAttribute("innerHTML", changeVal); //ie causes error doesn't work in ff or ch
       elem.value = changeVal; // works in ie and ff -- see note 2 on ch
    // elem.setAttribute("value", changeVal); // ie works; see note 1 on ff and note 2 on ch
    

    ie = internet explorer, ff = firefox, ch = google chrome. note 1: ff works until after value is deleted with backspace - see note by Ray Vega above. note 2: works somewhat in chrome - after update it is unchanged then you click away and click back into the field and the value appears. The best of the lot is elem.value = changeVal; which I did not comment out above.

提交回复
热议问题