如何在IE中复制内联样式元素? [英] How do you copy an inline style element in IE?

查看:103
本文介绍了如何在IE中复制内联样式元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IE不允许写入style或head元素的innerHTML属性。那么你如何将样式元素从一个文档的头复制到另一个文档?

IE does not allow writing to the innerHTML property of style or head elements. So how do you copy a style element from the head of one document to another?

推荐答案

function copy_style(src_style_tag) {    
    var tmp_div = document.createElement('div');
    var innerHTML = src_style_tag.innerHTML;
    tmp_div.innerHTML = '<p>x</p><style type="text/css">' + innerHTML + '</style>';

    return tmp_div.getElementsByTagName('style')[0];
}

魔术是你需要< p>标记在tmp_div的innerHTML中。没有它,IE不接受风格元素。

The magic is that you need the <p> tag in the innerHTML of the tmp_div. Without it, IE does not accept the style element.

这篇关于如何在IE中复制内联样式元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆