-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patha6react案例测试.html
68 lines (66 loc) · 1.55 KB
/
a6react案例测试.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.active {display:none}
</style>
<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>
<div id="example1"></div>
<div id="example2"></div>
<script type="text/babel">
function Check(props) {
console.log(props);
/* props参数是组件实例上所有的属性集合 */
var value=props.checked? "Checked":"Unchecked";
return (
<div className={value}
onClick={props.onClick}>
{props.children}
</div>
)
}
ReactDOM.render(
<Check checked={true} onClick={console.log.bind(console)}>
Hello,world!
</Check>,
document.getElementById("example")
)
function Check1(props) {
var {checked, ...other}=props;
console.log({...other});
/* 打印出来的...other里面没有实例中的checked属性 */
var attr=checked? "Checked":"Unchecked";
return (
<div className={attr}
{...other}>
{props.children}
</div>
)
}
/*
function Check2(props) {
var {checked,title,...other}=props;
var checkAttr=checked? "Checked":"Unchecked";
var titleAttr=checked? "Title":"No title";
return (
<div {...other}
className={checkAttr}
onClick={props.onClick}>
{titleAttr}
</div>
)
}
*/
ReactDOM.render(
<Check1 checked={true} onClick={console.log.bind(console)}>Hello,world!</Check1>,document.getElementById("example1")
)
</script>
</body>
</html>