IE8下用inerHTML得到pre元素的文本内容,但是格式不能保留。求解决方法 javascriptpreinnerHTML 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script src="jquery-1.8.3.min.js"></script><script>window.onload=function(){$("#p1").clone().appendTo($("#p2"));}</script></head><body><pre id='p1'> 123 sdf sdf</pre><pre id='p2'></pre></body></html> var str = document.getElementById('pre1').innerHTML; alert(str.charCodeAt(1)) document.getElementById('pre2').outerHTML = '<pre>'+str+'</pre>';判断为ie8-就用outerHTML,否则就用innerHTML,自己修改上面红色的兼容代码 谢谢版主的指教。 jquery我基本上不用,所以1楼贴的代码用不上了。 求一个新窗口打开的退弹代码 js load xml问题 javascript对象函数 如何打开网页自动加载文件的 梅花雪树的动态加载 **********js的简单问题,高手帮忙********** 怎么在弹出对话框中输入参数 如何做购物车 javascript 闭包问题求解 cookie的domain属性问题 html中利用iframe嵌入jsp页面的问题 Uncaught TypeError: Cannot read property 'parentNode' of undefined
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="jquery-1.8.3.min.js"></script>
<script>
window.onload=function(){$("#p1").clone().appendTo($("#p2"));}
</script>
</head>
<body>
<pre id='p1'>
123
sdf
sdf
</pre><pre id='p2'></pre>
</body>
</html>
var str = document.getElementById('pre1').innerHTML;
alert(str.charCodeAt(1))
document.getElementById('pre2').outerHTML = '<pre>'+str+'</pre>';
判断为ie8-就用outerHTML,否则就用innerHTML,自己修改上面红色的兼容代码
jquery我基本上不用,所以1楼贴的代码用不上了。