-
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Is Prime Number?</title> </head> <body> <script type="text/javascript"> var xNumber = +prompt("请输入一个大于1的数字:"); var isPrimeNumber = true; if(xNumber>1 && xNumber != NaN) { for(i=2; i<xNumber; i++) { if(xNumber%i==0) { isPrimeNumber = false; } } } if(isPrimeNumber) { document.write(xNumber+" is a Prime Number."); } else { document.write(xNumber+" is NOT a Prime Number."); } </script> </body> </html>