开发者

IE9 set innerHTML of textarea with html tags

开发者 https://www.devze.com 2023-02-21 07:59 出处:网络
I have this field In IE9 the following line gives me the error \'SCRIPT601: Unknown runtime error \' //option 1.

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 disap开发者_Go百科pears 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?


You should set the value property.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消