题目:当点击“开始”按钮时,div里面每隔一秒就有一个“hello”,”hello”依次累加,每个“hello”之间有一个空格分开。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
div{
width: 300px;
height: 300px;
border: 1px solid #333;
word-wrap: break-word;
word-break: normal;
}
</style>
<script type="text/javascript">
window.onload=function () {
var btn=document.getElementsByTagName("input")[0];
var div=document.getElementsByTagName("div")[0];
btn.onclick=function () {
function printWord() {
div.innerHTML+="hello ";
}
setInterval(printWord,1000);
}
}
</script>
</head>
<body>
<input type="button" value="开始">
<div></div>
</body>
</html>
运行截图