W3Schools jQuery测验

前端之家收集整理的这篇文章主要介绍了W3Schools jQuery测验前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在W3Schools网站上发布了一个jQuery测验…

http://www.w3schools.com/quiztest/quiztest.asp?qtest=jQuery@H_403_3@

问题#19如下,@H_403_3@

Look at the following jQuery selector: $(“div#intro .head”).@H_403_3@

What does it select?@H_403_3@

A. The first element with id=”head” inside any div element with class=”intro”@H_403_3@

B. All elements with class=”head” inside the first div element with id=”intro”@H_403_3@

C. All div elements with id=”intro” or class=”head”@H_403_3@

我选择答案B得到了正确的答案.@H_403_3@

我的问题与答案B的措辞有关.@H_403_3@

不应该从答案中删除“第一”这个词吗?@H_403_3@

B. All elements with class=”head” inside the div element with id=”intro”@H_403_3@

ID被定义为“元素的唯一标识符”,因此不能真正理解为什么它们会引用“带有id = intro的第一个div元素”@H_403_3@

我不相信它故意试图变得棘手,因为这个测验中的所有其他问题都非常简单.@H_403_3@

谢谢你的想法.@H_403_3@

编辑:@H_403_3@

我向W3Schools报告了这个错误并将它们引导到了这个主题.@H_403_3@

编辑#2:@H_403_3@

这是来自同一测验的另一个问题.@H_403_3@

Another questionable jQuery Quiz answer at W3Schools@H_403_3@

解决方法

你是对的,第一语言可以(应该)从所有选择中删除.

根据HTML 4.01 Spec:@H_403_3@

This attribute assigns a name to an
element. This name must be unique in a
document.@H_403_3@

另外,根据jQuery documentation for the id selector:@H_403_3@

Selects a single element with the
given id attribute@H_403_3@

引擎盖下,选择器使用document.getElementById("...").有趣的是,the specification为此功能指出:@H_403_3@

Behavior is not defined if more than
one element has this ID.@H_403_3@

因此,假设您有两个具有相同id的元素,该函数的结果是不可预测的并且特定于浏览器.@H_403_3@

旁注:W3Schools不被认为是学习JavaScript / jQuery的最佳场所之一.一个备受推崇的JavaScript替代品是MDC’s JavaScript Guide.对于jQuery,请查看tutorials页面.@H_403_3@

猜你在找的jQuery相关文章