jQuery学习笔记 08

jQuery学习笔记:
$(document).ready(function()
{
 $("a[@name]").css("background", "blue");
});

让文档中A元素,并且带name属性的那些对象,背景色变为blue。

问题一:
示例中原始的代码是:
$(document).ready(function() {
$("a[@name]").background("#eee");
});
运行时会出错,对象不支持此属性或方法。我找不到jQuery有background属性。

问题二:
XPath的示例:$("//input[@checked]")
前面是有带//号的,而这里,我用与不用都一样,为什么?

para selects the para element children of the context node
//para selects all the para descendants of the document root and thus selects all para elements in the same document as the context node

知识点:XPath
好象也不难,能理解 //title[@lang='eng'] 是什么意思就够了。
答案:选取所有 title 元素,且这些元素拥有值为 eng 的 lang 属性。

 

原文地址:https://www.cnblogs.com/yzx99/p/1257410.html