使用JavaScript / jQuery移除或替换样式表(< link>) [英] Removing or replacing a stylesheet (a <link>) with JavaScript/jQuery

查看:459
本文介绍了使用JavaScript / jQuery移除或替换样式表(< link>)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何做?

我尝试了

$('link[title="mystyle"]').remove();

虽然元素被删除,但样式仍然应用于当前页面Firefox)。

and although the element is removed, the styles are still applied to the current page (in both Opera and Firefox).

有没有其他方法?

推荐答案

迎合,你必须设置样式表被禁用,因为它保持css样式在内存中,所以删除元素将无法正常工作,它也可能导致它在某些情况下崩溃,如果我记得正确。

To cater for ie you have to set the stylesheet to be disabled as it keeps the css styles in memory so removing the element will not work, it can also cause it to crash in some instances if I remember correctly.

这也适用于跨浏览器。

例如

document.styleSheets[0].disabled = true;

//在您的情况下使用jquery try

//so in your case using jquery try

$('link[title=mystyle]')[0].disabled=true;

这篇关于使用JavaScript / jQuery移除或替换样式表(< link>)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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