IE9 set innerHTML of textarea with html tags

落花浮王杯 提交于 2019-12-07 13:53:09

问题


I have this field

In IE9 the following line gives me the error 'SCRIPT601: Unknown runtime error ' //option 1. document.getElementById('code').innerHTML = 'some text';

The error disappears and it seems to work (assiging empty value) when I change the line to: //option 2. document.getElementById('code').innerHTML = '';

The I tried this: //option 3. document.getElementById('code').innerHTML = escape('some text');

but then the HTML gets to be escaped and thats not what I want, I want this exact string to be placed in the textbox.

In Chrome and Firefox the code in option 1 does run correctly.

What can I do to fix this?


回答1:


You should set the value property.




回答2:


At a guess, does your webpage have a <!DOCTYPE html> or similar?

http://blogs.msdn.com/b/ie/archive/2011/03/24/ie9-s-document-modes-and-javascript.aspx




回答3:


In IE9 quirks mode accepted solution won't work.

As you are probably trying to set innerHtml for <p>, it will work if you replace <p> with <div>.

Credits: Theo Gray, http://www.theogray.com/blog/2009/06/internet-explorer-unknown-runtime-error



来源:https://stackoverflow.com/questions/5503806/ie9-set-innerhtml-of-textarea-with-html-tags

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