<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="button" id="btn1" value="-" />
<input type="text" id="box" value="10" />
<input type="button" id="btn2" value="+" />
<script type="text/javascript">
var oBtn1 = document.getElementById('btn1')
var oBtn2 = document.getElementById('btn2')
var oBox = document.getElementById('box')
oBtn1.onclick = function(){
var box = oBox.value
box--
if (box == 0) {
oBox.value = 1
alert('最少购买一件')
}else{
oBox.value = box
}
}
oBtn2.onclick = function(){
var box = oBox.value
box++
if (box >= 20) {
oBox.value = 20
alert('最多购买20件')
}else{
oBox.value = box
}
}
var sw = prompt('请输入您的年龄!!!')
sw>18? alert('欢迎光临'):alert('未成年禁止上网!!')
</script>
</body>
</html>
网友评论