Files
freeCodeCamp/curriculum/challenges/chinese/03-front-end-libraries/react/define-an-html-class-in-jsx.chinese.md
Oliver Eyton-Williams 61460c8601 fix: insert blank line after ```
search and replace ```\n< with ```\n\n< to ensure there's an empty line
before closing tags
2020-08-16 04:45:20 +05:30

1.6 KiB
Raw Blame History

id, title, challengeType, isRequired, videoUrl, localeTitle
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');
  - text: <code>div</code>有一类<code>myDiv</code> 。
    testString: assert.strictEqual(JSX.props.className, 'myDiv');

Challenge Seed

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

After Test

console.info('after the test');

Solution

// solution required

/section>