Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用jQuery设置样式表的位置?_Javascript_Jquery_Css - Fatal编程技术网

Javascript 如何使用jQuery设置样式表的位置?

Javascript 如何使用jQuery设置样式表的位置?,javascript,jquery,css,Javascript,Jquery,Css,如何使用jQuery设置样式表的位置?您可以像处理标记中的元素一样操作元素: $("head>link[href$=mystyle.css]").remove(); $('<link rel="stylesheet" href="/css/anotherstyle.css"/>').appendTo("head"); $(“head>链接[href$=mystyle.css]”)。删除(); $('')。附于(“标题”); 这将删除mystyle.css标记,并在元素末尾插

如何使用jQuery设置样式表的位置?

您可以像处理
标记中的元素一样操作
元素:

$("head>link[href$=mystyle.css]").remove();
$('<link rel="stylesheet" href="/css/anotherstyle.css"/>').appendTo("head");
$(“head>链接[href$=mystyle.css]”)。删除();
$('')。附于(“标题”);

这将删除
mystyle.css
标记,并在
元素末尾插入一个新的
标记,该标记带有
/css/anotherstyle.css

一种方法是给
元素一个ID,并将其用作选择器,更改匹配元素的
href
属性:

$("#myStyle")[0].href = "/path/to/new.css";
另一种方法是将多个样式表附加到文档中,并在必要时启用/禁用它们:

<link id="style1" href="style1.css" />
<link id="style2" href="style2.css" disabled="disabled" />

定期切换页面的所有样式时,这种方法是最好的。

请澄清。不能替换jquery中的文件,但可以更改样式表包含以指向其他样式表。
$("#style1").attr("disabled", true).next().attr("disabled", false);