freeCodeCamp/curriculum/challenges/chinese/01-responsive-web-design/basic-html-and-html5/add-placeholder-text-to-a-t...

2.1 KiB

id title challengeType videoUrl forumTopicId dashedName
bad87fee1348bd9aedf08830 给输入框添加占位符文本 0 https://scrimba.com/p/pVMPUv/cKdJDhg 16647 add-placeholder-text-to-a-text-field

--description--

占位符文本用户在 input 输入框中输入任何东西前的预定义文本。

你可以像这样创建一个占位符:

<input type="text" placeholder="this is placeholder text">

**注意:**别忘了 input 元素是 "自闭和标签",即不需要结束标签。

--instructions--

input 输入框的 placeholder 占位符文本设置为 "cat photo URL"。

--hints--

给现有的 input 输入框添加一个 placeholder 属性。

assert($('input[placeholder]').length > 0);

设置占位符属性的值为 cat photo URL

assert(
  $('input') &&
    $('input').attr('placeholder') &&
    $('input')
      .attr('placeholder')
      .match(/cat\s+photo\s+URL/gi)
);

input 元素不该有结束标签。

assert(!code.match(/<input.*\/?>.*<\/input>/gi));

input 输入框的语法必须正确。

assert($('input[type=text]').length > 0);

--seed--

--seed-contents--

<h2>CatPhotoApp</h2>
<main>
  <p>Click here to view more <a href="#">cat photos</a>.</p>

  <a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>

  <p>Things cats love:</p>
  <ul>
    <li>cat nip</li>
    <li>laser pointers</li>
    <li>lasagna</li>
  </ul>
  <p>Top 3 things cats hate:</p>
  <ol>
    <li>flea treatment</li>
    <li>thunder</li>
    <li>other cats</li>
  </ol>
  <input type="text">
</main>

--solutions--

<h2>CatPhotoApp</h2>
<main>
  <p>Click here to view more <a href="#">cat photos</a>.</p>

  <a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>

  <p>Things cats love:</p>
  <ul>
    <li>cat nip</li>
    <li>laser pointers</li>
    <li>lasagna</li>
  </ul>
  <p>Top 3 things cats hate:</p>
  <ol>
    <li>flea treatment</li>
    <li>thunder</li>
    <li>other cats</li>
  </ol>
  <input type="text" placeholder="cat photo URL">
</main>