<input type="number" id="x">
<button id="btn">查询</button>
<input type="text" id="y">
<script>
btn.onclick = function () {
var xx = x.value - 0;
var flag = 1;
for (var i = 2; i < xx; i++) {
if (xx % i == 0) {
flag = 2;
break;
}
}
flag == 1 ? y.value = '质数' : y.value = '合数';
}
</script>
转载请注明原文地址:https://ipadbbs.8miu.com/read-3708.html