IE9 set innerHTML of textarea with html tags

匿名 (未验证) 提交于 2019-12-03 08:54:24

问题:

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



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