1.7 KiB
1.7 KiB
id, challengeType, forumTopicId, title
id | challengeType | forumTopicId | title |
---|---|---|---|
5a24c314108439a4d4036160 | 6 | 301393 | 在 JSX 中定义一个 HTML Class |
Description
class
这个单词来定义 HTML 的 class 名。这是因为class
是 JavaScript 中的关键字。JSX 使用className
代替。
事实上,JSX 中所有 HTML 属性和事件引用的命名约定都变成了驼峰式。例如,JSX 中的单击事件是 onClick
,而不是 onclick
。同样,onchange
变成了onChange
。虽然这是一个微妙的差异,但请你一定要记住。
Instructions
myDiv
应用于 JSX 提供的div
上。
Tests
tests:
- text: 常量<code>JSX</code>应该返回一个<code>div</code>元素。
testString: assert.strictEqual(JSX.type, 'div');
- text: <code>div</code>有一个<code>myDiv</code>class。
testString: assert.strictEqual(JSX.props.className, 'myDiv');
Challenge Seed
const JSX = (
<div>
<h1>Add a class to this div</h1>
</div>
);
After Test
ReactDOM.render(JSX, document.getElementById('root'))
Solution
const JSX = (
<div className = 'myDiv'>
<h1>Add a class to this div</h1>
</div>);