2. React JSX语法及特点介绍
什么是JSX
JSX的特点
如何使用JSX(JSX语法)
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>jsx注释</title>
<script src="../build/react.js"></script>
<script src="../build/react-dom.js"></script>
<script src="../build/browser.min.js"></script>
</head>
<body>
<div id="example"></div>
<script type="text/babel">
ReactDOM.render(
<h1
/*
注释1
*/
name = "test" // 注释2
>Hello, world!</h1>,
document.getElementById('example')
);
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>jsx样式使用1className</title>
<script src="../build/react.js"></script>
<script src="../build/react-dom.js"></script>
<script src="../build/browser.min.js"></script>
<style type="text/css">
.text-red{
color : red
}
</style>
</head>
<body>
<div id="example"></div>
<script type="text/babel">
ReactDOM.render(
//元素不能直接写class因为class在es是关键字,无法被识别。要使用className替换原来的class属性。
//<h1 class='text-red'>Hello, world!</h1>,
<h1 className='text-red'>Hello, world!</h1>,
document.getElementById('example')
);
</script>
</body>
</html>
<body>
<div id="example"></div>
<script type="text/babel">
var style = {
color : "red",
//这里只能用驼峰命名不能用font-size
fontSize:'88px'
};
ReactDOM.render(
<h1 style={style}>Hello, world!</h1>,
//也可以在React中使用style
//<h1 style={{color:'red'}}>Hello, world!</h1>,
document.getElementById('example')
);
</script>
</body>
<body>
<script type="text/babel">
var HelloWorld = React.createClass({
render: function () {
return <p>Hello, {this.props.name ? this.props.name : "World"}</p>
}
});
//ReactDOM.render(<HelloWorld></HelloWorld>, document.body);
ReactDOM.render(<HelloWorld name='Jerome'></HelloWorld>, document.body);
</script>
</body>
<body>
<script type="text/babel">
var HelloWorld = React.createClass({
getName: function () {
if (this.props.name)
return this.props.name
else
return "World"
},
render: function () {
var name = this.getName();
return <p>Hello, {name}</p>
}
});
//ReactDOM.render(<HelloWorld></HelloWorld>, document.body);
ReactDOM.render(<HelloWorld name='Jerome'></HelloWorld>, document.body);
</script>
</body>
<body>
<script type="text/babel">
var HelloWorld = React.createClass({
getName: function () {
if (this.props.name)
return this.props.name
else
return "World"
},
render: function () {
return <p>Hello, {this.getName()}</p>
}
});
//ReactDOM.render(<div><HelloWorld></HelloWorld></div>, document.body);
ReactDOM.render(<HelloWorld name='Jerome'></HelloWorld>, document.body);
</script>
</body>
<body>
<script type="text/babel">
var HelloWorld = React.createClass({
render: function () {
// 左边如果有直就返回左边的,否则返回右边的。
return <p>Hello, {this.props.name || "World"}</p>
}
});
//ReactDOM.render(<div><HelloWorld></HelloWorld></div>, document.body);
ReactDOM.render(<HelloWorld name='Jerome'></HelloWorld>, document.body);
</script>
</body>
<body>
<script type="text/babel">
var HelloWorld = React.createClass({
render: function () {
return <p>Hello, {(function (obj) {
if (obj.props.name)
return obj.props.name
else
return "World"
})(this)}</p>
}
});
//ReactDOM.render(<div><HelloWorld></HelloWorld></div>, document.body);
ReactDOM.render(<HelloWorld name='Jerome'></HelloWorld>, document.body);
</script>
</body>
非DOM 属性介绍
<body>
<script type="text/babel">
// dangerouslySetInnerHTML:在JSX中直接插入HTML代码
var rawHTML = {
__html: "<h1>I'm inner HTML</h1>"
};
var HelloWorld = React.createClass({
render: function () {
return <p>Hello, World</p>
}
});
ReactDOM.render(<div dangerouslySetInnerHTML={rawHTML}></div>, document.body);
</script>
</body>
2. React JSX语法及特点介绍的更多相关文章
- React的jsx语法,详细介绍和使用方法!
jsx语法 一种混合使用html及javascript语法的代码 在js中 遇到<xx>即开始html语法 遇到</xx>则结束html语法 恢复成js语法 例如: let D ...
- React JSX语法说明
原文:http://my.oschina.net/leogao0816/blog/379487 什么是JSX? 在用React写组件的时候,通常会用到JSX语法,粗看上去,像是在Javascript代 ...
- React(JSX语法)-----JSX基本语法
JSX------HTML tags vs React Components: 1.To render a html tag,just use lower-case tag names in JSX; ...
- react.js 从零开始(三)JSX 语法及特点介绍
什么是jsx? jsx = JavaScript + xml jsx 是一种 Ecmascript 的一种新标准. jsx 是一种 带有结构性的语法. jsx 的特点: 1.类xml语法易于理解. 2 ...
- JSX语法及特点介绍
1.1 基本语法 1)自定义组件名首字母大写:元素名即组件名,首字母需要大写.首字母小写时React会以为这是HTML的标准标签,因此自定义的组件名需要首字母大写,否则会报错. 2)嵌套:在rende ...
- 学习 React(jsx语法) + es2015 + babel + webpack
视频学习地址: http://www.jtthink.com/course/play/575 官方地址 https://facebook.github.io/react/ 神坑: 1.每次this.s ...
- React(JSX语法)----动态UI
1.React honws how to bubble and capture events according to the spec,and events passed to your event ...
- React(JSX语法)----JSX拼写
注意:For DOM differences,such as the inline style attribute,check here. // bad: it displays "FIrs ...
- React(JSX语法)-----JSX属性
1. if you know all the propertities that you want to place on a component ahead of time,it is easy t ...
随机推荐
- hdu 5016 点分治(2014 ACM/ICPC Asia Regional Xi'an Online)
Mart Master II Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- 2015 多校联赛 ——HDU5360(贪心+优先队列)
Sample Input 4 8 4 1 3 2 2 1 0 3 5 3 6 4 2 1 7 6 8 3 3 2 0 5 0 3 6 4 5 2 7 7 6 7 6 8 2 2 3 3 3 0 0 2 ...
- bzoj 3174: [Tjoi2013]拯救小矮人
Description 一群小矮人掉进了一个很深的陷阱里,由于太矮爬不上来,于是他们决定搭一个人梯.即:一个小矮人站在另一小矮人的 肩膀上,知道最顶端的小矮人伸直胳膊可以碰到陷阱口.对于每一个小矮人, ...
- 中断API之setup_irq【转】
转自:https://blog.csdn.net/tiantao2012/article/details/78957472 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blo ...
- Linux下用程序实现统计cpu和内存的利用率
Linux下没有直接可以调用系统函数知道CPU占用和内存占用.那么如何知道CPU和内存信息呢.只有通过proc伪文件系统来实现. proc伪文件就不介绍了,只说其中4个文件.一个是/proc/stat ...
- 关闭默认共享,禁止ipc$空连接
关闭默认共享,禁止ipc$空连接 要防止别人用ipc$和默认共享入侵,需要禁止ipc$空连接,避免入侵者取得用户列表,并取消默认共享 禁止ipc$空连接进行枚举运行regedit,找到如下组键[HKE ...
- drool-6.5的自学demo
先丢代码地址 https://gitee.com/a247292980/drools 再丢pom.xml <project xmlns="http://maven.apache.org ...
- 安装Leanote极客范的云笔记
前言 在这个互联网知识呈爆炸增长的时代,作为一个程序员要掌握的知识越来越多,然再好的记性也不如烂笔头,有了笔记我们就是可以时常扒拉扒拉以前的知识,顺便可以整理下自己的知识体系. 如今市面上云笔记产品, ...
- python学习之路前端-CSS
CSS概述 css是英文Cascading Style Sheets的缩写,称为层叠样式表,用于对页面进行美化. 存在方式有三种:元素内联.页面嵌入和外部引入,比较三种方式的优缺点. 语法:style ...
- 全网代理公开ip爬取(隐藏元素混淆+端口加密)
简述 本次要爬取的网站是全网代理,貌似还是代理ip类网站中比较有名的几个之一,其官网地址: http://www.goubanjia.com/. 对于这个网站的爬取是属于比较悲剧的,因为很久之前就写好 ...