时间:2021-07-01 10:21:17 帮助过:8人阅读
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
#btn
{
width:200px;
height:50px;
background -color:gary;
}
</style>
<script type="text/javascript">
onload = function () {
//获得该button对象
var btn = document.getElementById('btn');
//创建计时器 返回计时器ID
var intervalId = setInterval(function () {
var waitSecond = parseInt((/\d+/).exec(btn.value));//利用RegExp.exec()方法,返回匹配的字符串内容
waitSecond--;//时间--
if (waitSecond >= 0) {//判断
btn.value=btn.value.replace(/\d+/, waitSecond) //利用string.repleace(RegExp,code)方法替换按钮value中数字,并返回替换结果
} else {
btn.value = '同意';//将按钮value值改为同意
btn.disabled = false;//将按钮disabled值改为false
clearInterval(intervalId);//清除计时器
}
}, 1000);
};
</script>
</head>
<body>
<input type="button" name="name" value="请仔细阅读5秒后点击同意继续" id="btn" disabled="disabled"/>
</body>
</html>