4.8 KiB
4.8 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
bad87fee1348bd9aede08817 | Nest an Anchor Element within a Paragraph | 0 | 在段落中嵌入锚元素 |
Description
<P>让我们分解示例:普通文本包含在
这是一个<a target="_blank" href="http://freecodecamp.org"> freecodecamp.org </a>的链接供您关注。
</ p>
p
元素中: <p> Here's a ... for you to follow. </p>
接下来是anchor
元素<a>
(需要结束标记</a>
): <a> ... </a>
target
是一个锚标记属性,指定打开链接的位置,值"_blank"
指定在新标签中打开链接href
是一个锚标记属性,其中包含URL地址链接: <a href="http://freecodecamp.org"> ... </a>
在名为anchor text
的锚元素中,文本“链接到freecodecamp.org”将显示一个单击的链接: <a href=" ... ">link to freecodecamp.org</a>
示例的最终输出如下所示: 这是freecodecamp.org的链接供您关注。
Instructions
a
新元素内p
元(刚过现有的main
元素)。新段落的文本应显示“查看更多猫照片”,其中“猫照片”是一个链接,其余文本是纯文本。 Tests
tests:
- text: '您需要一个链接到“http://freecatphotoapp.com” <code>a</code>元素。'
testString: 'assert(($("a[href=\"http://freecatphotoapp.com\"]").length > 0 || $("a[href=\"http://www.freecatphotoapp.com\"]").length > 0), "You need an <code>a</code> element that links to "http://freecatphotoapp.com".");'
- text: 你<code>a</code>元素应该有“猫照片”的锚文本
testString: 'assert($("a").text().match(/cat\sphotos/gi), "Your <code>a</code> element should have the anchor text of "cat photos"");'
- text: 创建一个新的<code>p</code>周围的元素<code>a</code>元素。 HTML代码中应至少包含3个<code>p</code>标签。
testString: 'assert($("p") && $("p").length > 2, "Create a new <code>p</code> element around your <code>a</code> element. There should be at least 3 total <code>p</code> tags in your HTML code.");'
- text: 您<code>a</code>元素应嵌套在新的<code>p</code>元素中。
testString: 'assert(($("a[href=\"http://freecatphotoapp.com\"]").parent().is("p") || $("a[href=\"http://www.freecatphotoapp.com\"]").parent().is("p")), "Your <code>a</code> element should be nested within your new <code>p</code> element.");'
- text: 你的<code>p</code>元素应该有“查看更多”文本(后面有一个空格)。
testString: 'assert(($("a[href=\"http://freecatphotoapp.com\"]").parent().text().match(/View\smore\s/gi) || $("a[href=\"http://www.freecatphotoapp.com\"]").parent().text().match(/View\smore\s/gi)), "Your <code>p</code> element should have the text "View more " (with a space after it).");'
- text: 您的<code>a</code>元素<em>不</em>应该有文字“查看更多”。
testString: 'assert(!$("a").text().match(/View\smore/gi), "Your <code>a</code> element should <em>not</em> have the text "View more".");'
- text: 确保每个<code>p</code>元素都有一个结束标记。
testString: 'assert(code.match(/<\/p>/g) && code.match(/<p/g) && code.match(/<\/p>/g).length === code.match(/<p/g).length, "Make sure each of your <code>p</code> elements has a closing tag.");'
- text: 确保每个的<code>a</code>元素具有一个结束标记。
testString: 'assert(code.match(/<\/a>/g) && code.match(/<a/g) && code.match(/<\/a>/g).length === code.match(/<a/g).length, "Make sure each of your <code>a</code> elements has a closing tag.");'
Challenge Seed
<h2>CatPhotoApp</h2>
<main>
<a href="http://freecatphotoapp.com" target="_blank">cat photos</a>
<img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
</main>
Solution
// solution required