1个回答
推荐于2016-04-30
展开全部
<!DOCTYPE HTML>
<html>
<head>
<meta charset=UTF-8>
<title>recursion</title>
<style type="text/css">
</style>
<script type="text/javascript">
onload = function ()
{
var txt = document.createElement ('input');
txt.type = 'text';
txt.value = 1;
var startBtn = document.createElement ('input');
startBtn.type = 'button';
startBtn.value = 'start';
startBtn.onclick = function ()
{
if (!this.interval)
{
this.interval = setInterval (function ()
{
txt.value++;
}, 1000);
this.disabled = 'disabled';
}
};
var stopBtn = document.createElement ('input');
stopBtn.type = 'button';
stopBtn.value = 'stop';
stopBtn.onclick = function ()
{
if (!!startBtn.interval)
{
clearInterval (startBtn.interval);
startBtn.removeAttribute ('disabled');
startBtn.interval = null;
}
};
var body = document.body;
body.appendChild (txt);
body.appendChild (startBtn);
body.appendChild (stopBtn);
};
</script>
</head>
<body>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询