<input type="text" id="content" value="0" />
<button id="plus" onclick="p()">点击加1</button>
<button id="minus" onclick="m()">点击减1</button>
<script type="text/javascript">
var plus = document.getElementById('plus')
var minus = document.getElementById('minus')
function p(){
var content = document.getElementById('content').value
if(content >= 20){
alert("数字已经超过20")return
} else{
content++
}
document.getElementById('content').value = content
}
function m(){
var content = document.getElementById('content').value
if(content <= 0){
alert("数字已经小于0")return
} else{
content--
}
document.getElementById('content').value = content
}
</script>
你好,可以这样写:<div id="test">5</div>
<script type="text/javascript">
var i = 4
var t = setInterval(function(){
if (i == 0) {
clearInterval(t)
return
}
document.getElementById("test").innerHTML = i
i--
}, 1000)
</script>
望采纳