W3Schools jQuery测验 [英] W3Schools jQuery Quiz

查看:63
本文介绍了W3Schools jQuery测验的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在W3Schools网站上发布了一个jQuery测验...

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

问题19如下,

查看以下jQuery选择器:$("div#intro .head").

它选择了什么?

A.任何具有class ="intro"的div元素中第一个具有id ="head"的元素

B.所有具有id ="intro"的第一个div元素内具有class ="head"的所有元素

C.所有id ="intro"或class ="head"的div元素

我通过选择答案B来弄对了.

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

不是应该从答案中删除"first"一词吗?

B. div元素中id ="intro"

内所有class ="head"的元素

ID被定义为元素的唯一标识符",因此无法真正理解为什么他们会引用ID为" first " div元素的原因= intro"

我不认为这样做是有意的,因为本测验中的所有其他问题都很简单.

谢谢您的想法.


我将此错误报告给W3Schools,并将其定向到该线程.


编辑#2:

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

在W3Schools另一个可疑的jQuery测验答案

解决方案

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

根据 HTML 4.01规范:

此属性将名称分配给 元素.此名称在一个名称中必须是唯一的 文档.

此外,根据jQuery 有关ID选择器的文档:

使用 给定id属性

在后台,选择器使用 document.getElementById("...") .有趣的是,为此规范功能状态:

行为不定义,如果超过 一个元素具有此ID.

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

侧注:W3Schools并不是学习JavaScript/jQuery的最佳场所之一.一个受人尊敬的JavaScript替代方法是 MDC的JavaScript指南.对于jQuery,请查看教程页.

There is a jQuery quiz posted on the W3Schools site here...

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

Question #19 is as follows,

Look at the following jQuery selector: $("div#intro .head").

What does it select?

A. The first element with id="head" inside any div element with class="intro"

B. All elements with class="head" inside the first div element with id="intro"

C. All div elements with id="intro" or class="head"

I got it correct by picking answer B.

My question has to do with the wording of answer B.

Shouldn't the word, "first", be removed from the answer?

B. All elements with class="head" inside the div element with id="intro"

ID is defined as "a unique identifier to an element", so not really understanding why they would refer to the "the first div element with id=intro"

I don't believe that it's intentionally trying to be tricky as all the other questions in this quiz are very straightforward.

Thank-you for your thoughts.


EDIT:

I reported this error to W3Schools and directed them to this thread.


EDIT #2:

This is another question from the same quiz.

Another questionable jQuery Quiz answer at W3Schools

解决方案

You are correct, the first language could (should) be removed from all choices.

According to the HTML 4.01 Spec:

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

Additionally, according to the jQuery documentation for the id selector:

Selects a single element with the given id attribute

Under the hood, the selector uses document.getElementById("..."). Interestingly, the specification for this function states:

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

So, assuming you do have two elements with the same id, results of the function are unpredictable and browser-specific.

Sidenote: W3Schools is not regarded as one of the best places to learn JavaScript / jQuery. A well-respected alternative for JavaScript is MDC's JavaScript Guide. For jQuery, check out the tutorials page.

这篇关于W3Schools jQuery测验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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