React实现按钮控制倒计时
来源:互联网 发布:摄影网络教学 编辑:程序博客网 时间:2024/06/05 19:01
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="https://cdn.bootcss.com/react/15.4.2/react.min.js"></script>
<script src="https://cdn.bootcss.com/react/15.4.2/react-dom.min.js"></script>
<script
src="https://cdn.bootcss.com/babel-standalone/6.22.1/babel.min.js"></script>
</head>
<body>
<div id="example"></div>
<script type="text/babel">
var LikeButton = React.createClass({
getInitialState: function(){
return {
count: 30,
liked: true,
flag:true,
stop:true,
};
},
handleClick: function(){
clearInterval(this.timer);
this.state.stop=false;
this.state.flag = !this.state.flag;
if (this.state.flag) {
this.setState({
liked:true,
count: this.state.count
});
}else{
if(this.state.liked){
this.timer = setInterval(function () {
var count = this.state.count;
this.state.liked = false;
count -= 1;
if (count < 1) {
this.setState({
liked: true
});
count = 30;
clearInterval(this.timer);
}
this.setState({
count: count
});
}.bind(this), 1000);
}
}
},
render: function(){
var text = this.state.stop ? '点击开始计时' : this.state.count + '秒';
return(
<p>
<button onClick={this.handleClick}>{text}</button>
</p>
)}
});
ReactDOM.render(
<LikeButton />,
document.getElementById('example')
);
</script>
</body>
</html>
<html>
<head>
<script src="https://cdn.bootcss.com/react/15.4.2/react.min.js"></script>
<script src="https://cdn.bootcss.com/react/15.4.2/react-dom.min.js"></script>
<script
src="https://cdn.bootcss.com/babel-standalone/6.22.1/babel.min.js"></script>
</head>
<body>
<div id="example"></div>
<script type="text/babel">
var LikeButton = React.createClass({
getInitialState: function(){
return {
count: 30,
liked: true,
flag:true,
stop:true,
};
},
handleClick: function(){
clearInterval(this.timer);
this.state.stop=false;
this.state.flag = !this.state.flag;
if (this.state.flag) {
this.setState({
liked:true,
count: this.state.count
});
}else{
if(this.state.liked){
this.timer = setInterval(function () {
var count = this.state.count;
this.state.liked = false;
count -= 1;
if (count < 1) {
this.setState({
liked: true
});
count = 30;
clearInterval(this.timer);
}
this.setState({
count: count
});
}.bind(this), 1000);
}
}
},
render: function(){
var text = this.state.stop ? '点击开始计时' : this.state.count + '秒';
return(
<p>
<button onClick={this.handleClick}>{text}</button>
</p>
)}
});
ReactDOM.render(
<LikeButton />,
document.getElementById('example')
);
</script>
</body>
</html>
阅读全文
1 0
- React实现按钮控制倒计时
- js控制按钮倒计时
- react-native 自定义倒计时按钮
- JS实现按钮倒计时
- CountDownTimer实现点击按钮倒计时
- Android实现倒计时的按钮
- 点击按钮实现倒计时效果
- CountDownTimer倒计时按钮的实现
- Android实现倒计时的按钮
- Android 倒计时按钮的实现
- 按钮倒计时的实现 iOS
- React Native实现验证码倒计时功能
- React Native按钮的实现
- jquery 实现验证码倒计时 点击按钮后倒计时效果
- 实现按钮倒计时效果(js)
- Javascript应用--实现倒计时按钮效果
- Android 4.0以上简单实现倒计时按钮
- 实现button按钮上的倒计时
- MySQL 5.7 EXPLAIN EXTENDED语句说明
- 次小生成树
- debug有感
- Python网络爬虫1
- vue.js 2.0实现的简单分页
- React实现按钮控制倒计时
- 基于vue2.0的一个分页组件
- dns-prefetch对网站速度能提升有多少?详解dns-prefetch
- Hibernate的入门
- Practical Microservices-Packt Publishing(2017) 读书笔记
- Python标准异常总结
- 基于vuejs菜单实现
- Android中的数据库应用小结
- Java Class.forName()