Files
freeCodeCamp/curriculum/challenges/chinese/03-front-end-libraries/react/define-an-html-class-in-jsx.md
Oliver Eyton-Williams ee1e8abd87 feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

1.3 KiB
Raw Blame History

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
5a24c314108439a4d4036160 在 JSX 中定义一个 HTML Class 6 301393 define-an-html-class-in-jsx

--description--

现在你已经习惯了编写 JSX你可能想知道它与 HTML 有什么不同。

到目前为止HTML 和 JSX 似乎完全相同。

JSX 的一个关键区别是你不能再使用class这个单词来定义 HTML 的 class 名。这是因为class是 JavaScript 中的关键字。JSX 使用className代替。

事实上JSX 中所有 HTML 属性和事件引用的命名约定都变成了驼峰式。例如JSX 中的单击事件是 onClick,而不是 onclick。同样,onchange变成了onChange。虽然这是一个微妙的差异,但请你一定要记住。

--instructions--

将 classmyDiv 应用于 JSX 提供的div上。

--hints--

常量JSX应该返回一个div元素。

assert.strictEqual(JSX.type, 'div');

div有一个myDivclass。

assert.strictEqual(JSX.props.className, 'myDiv');

--seed--

--after-user-code--

ReactDOM.render(JSX, document.getElementById('root'))

--seed-contents--

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

--solutions--

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