有人能解释一下这个Jquery吗

有人能解释一下这个Jquery吗,jquery,Jquery,我没有得到这部分:$(“link[rel=stylesheet]:not(:first)”)。attr它选择所有link标记,这些标记具有名为rel的属性,其值为stylesheet,并且不是第一个标记。例如,如果您有: $(document).ready(function () { if ((screen.width >= 1024) && (screen.height >= 768)) { alert('Screen size: 1024x

我没有得到这部分:
$(“link[rel=stylesheet]:not(:first)”)。attr
它选择所有
link
标记,这些标记具有名为
rel
的属性,其值为
stylesheet
,并且不是第一个标记。例如,如果您有:

$(document).ready(function () {
    if ((screen.width >= 1024) && (screen.height >= 768)) {
        alert('Screen size: 1024x768 or larger');
        $("link[rel=stylesheet]:not(:first)").attr({
            href: "style2.css"
        });
    } else {
        alert('Screen size: less than 1024x768, 800x600 maybe?');
        $("link[rel=stylesheet]:not(:first)").attr({
            href: "style1.css"
        });
    }
});

选择器将选择最后两个
链接
标记。为什么?因为它排除了第一个,因为
rel
属性的值不是
样式表
,而是
图标
;并排除第二个,因为它是所有具有属性
rel=“stylesheet”
链接中的第一个,而
不(:first)
会过滤掉这个链接

<link rel="icon" />
<link rel="stylesheet" href="style2.css" />
<link rel="stylesheet" href="style3.css" />
<link rel="stylesheet" href="style4.css" />

把它分解成几个部分。本例中的选择器将匹配任何
元素,该元素具有等于
样式表的
rel
属性,但它不是它找到的(
:first
)元素。找到的时候。Jquery附加了一个
href
属性,该属性等于浏览器窗口大小的样式表。。。breathe

链接[rel=stylesheet]将选择具有属性的所有标记rel=“stylesheet”


:not(:first)将过滤掉第一个CSS选择器。在这个特定的示例中,所有rel值为“stylesheet”的链接标记都被选中,但是遇到的第一个链接标记将被忽略

以下内容非常有助于掌握选择器:

W3学校参考:


Nettuts文章:

感谢您的快速重播和帮助:)
$("link[rel=stylesheet]:not(:first)").attr({href : "style1.css"});