-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
55 lines (48 loc) · 1.26 KB
/
script.js
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
const BOX_NAME = 'testname';
var CB = React.createClass({
onCheckClick: function(el) {
console.log('clicked '+ el);
},
render: function() {
const cbs = ['checkbox1', 'checkbox2', 'checkbox3'];
const list = cbs.map( (el, i) => {
return (
<li key={i}>
<input type="checkbox"
onClick={ e => this.onCheckClick(el) }
name={ BOX_NAME }
value={ el } />
</li>
);
}, this);
return (
<div>
<Nav boxName={ BOX_NAME } />
<ul>{ list }</ul>
</div>
);
}
});
var Nav = React.createClass({
handleCheckClick: function() {
console.log('select all');
const boxes = document.getElementsByName( this.props.boxName );
for ( let i = 0; i < boxes.length; i++ ) {
//boxes[i].checked = checked;
//boxes[i].onClick();
const evt = new MouseEvent( 'click', {
bubbles: true,
cancelable: true,
view: window,
} );
boxes[i].dispatchEvent( evt );
}
},
render: function() {
return <a onClick={ e => this.handleCheckClick() }>select all</a>;
}
});
ReactDOM.render(
<CB />,
document.getElementById('container')
);