<!DOCTYPE html>
<html>
<head>
<title>时间自增</title>
<script type="text/javascript">
function timedText(){
setInterval(function(){
var a = document.getElementById('txt');
a.value = parseInt(a.value)+1;
//console.log(typeof(a));
},1000);
}
</script>
</head>
<body>
<form>
<input type="button" value="显示时间!" onclick="timedText()"/>
<input type="text" id="txt" value=0 />
</body>
</html>
注意:
因为题目给定的表单中文本框是string型,要注意转成number型
setInterval用法