JavaScript   发布时间:2022-04-16  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了javascript – jQuery.clone()IE问题大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一些使用jQuery.clone()来获取页面的html,然后将其添加到pre标签.它在Firefox和Chrome中正常运行,但在IE中没有任何反应:
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script>
$(function(){

  $('button').click(function(){
    var $clone = $('html').clone();
    $('#output').text($clone.html());
  });

});
</script>
<style>
  article,aside,figure,footer,header,hgroup,menu,nav,section { display: block; }
</style>
</head>
<body>
  <button>run test</button>
  <pre id="output"></pre>
</body>
</html>

有没有知道IE的错误阻止这个,或者我做错了什么?

(我需要克隆它,因为我在输出之前对它进行了一些更改)

解决方法

如果您只想在页面中显示页面文本,请尝试以下操作:
$('button').click(function(){
  $('#output').empty().html(('<html>\n  ' + $('html').html() + '\n</html>')
     .replace(/&/gm,'&amp;')
     .replace(/</gm,'&lt;')
     .replace(/>/gm,'&gt;')
     .replace(/\r/gm,'')
     .replace(/\n/gm,'<br>')
   );
});

这适用于Chrome,Firefox和IE8.

大佬总结

以上是大佬教程为你收集整理的javascript – jQuery.clone()IE问题全部内容,希望文章能够帮你解决javascript – jQuery.clone()IE问题所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: