<!DOCTYPE html>
<html>
<head>
<title>Timer</title>
<style type="text/css">
#timer{
float:right;width:500px;
background:gold;
}
#message{
background:yellowgreen;
margin-right:500px;
}
</style>
<script type="text/javascript" src="//cdnjscn.b0.upaiyun.com/libs/react/0.11.1/react.js"></script>
<script type="text/javascript" src="//cdnjscn.b0.upaiyun.com/libs/react/0.11.1/JSXTransformer.js"></script>
</head>
<body>
<blockquote>
<div id="timer" ></div>
<div id="message"></div>
</blockquote>
<script type="text/jsx">
/** @jsx React.DOM */
var Timer = React.createClass({
getInitialState: function() {
return {secondsElapsed: 0};
},
tick: function() {
this.setState({secondsElapsed: this.state.secondsElapsed + 1});
},
componentDidMount: function() {
console.log("started");
this.interval = setInterval(this.tick, 1000);
},
render: function() {
return (
<h1>Seconds Elapsed: {this.state.secondsElapsed}</h1>
);
}
});
React.render(
<Timer />,
document.getElementById('timer')
);
var Message = React.createClass({
render: function() {
return <h1>Hello, <br/> {this.props.name}!</h1>;
}
});
React.render(
<Message name="xxxWorld" />,
document.getElementById('message')
);
</script>
</body>
</html>
比如这个页面,左面是信息 右面是定时器,如果要实现定时器超过100以后,改变左面的信息,怎么样实现通知呢?
6 回复