<html lang="en">
<head>
<title>奇偶数</title>
</head>
<body>
<input type=text>
<input type=button value="判断" onclick="chk(value)">
<p id="demo"></p>
<script>
function chk(num) {
var inputs = document.getElementsByTagName('input')[0]
var value = inputs.value
num = value
console.log(num)
alert((num % 2 == 0) ? "偶数" : "奇数") //判断是否能整除2
}
</script>
</body>
</html>
var num = prompt("请输入一个数字","")function fun(num){
var a = parseInt(num)
switch(a%2){
case 0:
document.write("是偶数")
break
case 1:
document.write("是奇数")
break
default:
alert("不是数字,请重新输入")
var num = prompt("请输入一个数字","")
fun(num)
break
}
}
fun(num)
<script type="text/JavaScript">var num = prompt("请输入一个数字","")
function fun(num){
var a = parseInt(num)
switch(a%2){
case 0:
document.write("是偶数")
break
case 1:
document.write("是奇数")
break
default:
alert("不是数字,请重新输入")
var num = prompt("请输入一个数字","")
fun(num)
break
}
}
fun(num)
</script>