使用jQuery更改样式表 [英] Changing a stylesheet using jQuery

查看:113
本文介绍了使用jQuery更改样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在html的div标签中使用jquery更改样式表?或更改样式表的jquery代码是什么?

How can I change a stylesheet using jquery in div tag on html? or what is the jquery code for changing stylesheets?

在javascript中,我们使用以下代码:

in javascript, we use the below code :

<script type="text/javascript">
 function changeStyle() {
 document.getElementById('stylesheet').href = 'design4.css';
 }
</script>

是否有jQuery方式?

Is there a jQuery way?

推荐答案

有更好的方法来执行您要的操作,但是如果您确实要使用jquery删除并添加远程样式表,则可以执行以下操作:

there are better ways to do what you're asking but if you really want to remove and add a remote stylesheet with jquery you can do this:

$('link[href^=old_css_file.css]').attr('href', '/path_to_new_css/file.css');

详细了解 ^=属性选择器

read more about the ^= attribute selector and the attr() function

这篇关于使用jQuery更改样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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