<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>
按照你的要求编写的js求100以内的偶数个数的程序如下
var even=0
for(var i=0i<100i++){
if(i%2==0){
even++
}
}
document.write("100以内的偶数有"+even+"个")