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.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


jQuery表单验证提交:前台验证一(图文+视频)
jQuery表单验证提交:前台验证二(图文+视频)
jQuery如何实时监听获取input输入框的值
JQuery怎么判断元素是否存在
jQuery如何实现定时重定向
jquery如何获取复选框选中的值
jQuery如何清空form表单数据
jQuery怎么删除元素节点
JQuery怎么循环输出数组元素
jquery怎么实现点击刷新当前页面
怎么用jquery实现文字左右展开收缩效果
jquery怎么删除html属性
如何用jquery实现图片翻转效果
jquery怎么删除样式属性
jquery如何获取当前元素的位置
如何用jquery实现点击展开收缩效果
jquery怎么实现点击隐藏显示效果
jQuery如何获取当前页面url
jQuery怎么获取鼠标的位置坐标
简洁易懂的jQuery:HTML表单与jQuery