<html leng = 'en'>
<head>
<meta charset = 'UTF-8'/>
</head>
<body>
<script>
function prime(){
for(var i = 2i <= 1000i++){
var num = 0
for(var j = 2j <= 1000j++){
if(i % j === 0){
num++
}
}
if(num === 1){
console.log(i)
}
}
}
prime()
</script>
</body>
</html>
<html><head>
<meta charset="utf-8">
</head>
<script type="text/javascript">
function show(){
var base=document.getElementById('base').value
isPrime(base)?alert(base+' 是素数'):alert(base+' 不是素数')
}
function isPrime(number) {
if (number < 2) {
return false
} else {
for (var j = 2 j <= Math.sqrt(number) j++) {
if (number % j == 0) {
return false
}
}
}
return true
}
function filter(obj) {
var r = /^\d+$/
var r2 = /\D+/
if (!r.test(obj.value)) {
obj.value = obj.value.replace(r2, '')
}
}
function filter2(obj){
var r2 = /\D+/g
clipboardData.setData('text',clipboardData.getData('text').replace(r2,''))
}
</script>
<body>
数字<input type='input' id='base' onkeyup='filter(this)' onbeforepaste="filter2()"/>
<br>
<input type="button" value="判断是否为素数" onclick="show()">
</body>
</html>