freeCodeCamp/curriculum/challenges/chinese/03-front-end-libraries/react/define-an-html-class-in-jsx...

1.7 KiB
Raw Blame History

id title challengeType isRequired videoUrl localeTitle
5a24c314108439a4d4036160 Define an HTML Class in JSX 6 false 在JSX中定义HTML类

Description

现在您已经开始编写JSX了您可能想知道它与HTML的区别。到目前为止似乎HTML和JSX完全相同。 JSX的一个关键区别是你不能再使用单词class来定义HTML类。这是因为class是JavaScript中的保留字。相反JSX使用className 。事实上JSX中所有HTML属性和事件引用的命名约定都变成了camelCase。例如JSX中的单击事件是onClick ,而不是onclick 。同样, onchange变为onChange 。虽然这是一个微妙的差异,但重要的是要记住前进。

Instructions

将一个myDivmyDiv JSX代码中提供的div

Tests

tests:
  - text: 常量<code>JSX</code>应该返回一个<code>div</code>元素。
    testString: 'assert.strictEqual(JSX.type, "div", "The constant <code>JSX</code> should return a <code>div</code> element.");'
  - text: <code>div</code>有一类<code>myDiv</code> 。
    testString: 'assert.strictEqual(JSX.props.className, "myDiv", "The <code>div</code> has a class of <code>myDiv</code>.");'

Challenge Seed

const JSX = (
  <div>
    <h1>Add a class to this div</h1>
  </div>
);

After Test

console.info('after the test');

Solution

// solution required