比较的时候当字符串比较了<HTML>
<HEAD>
<TITLE>寻找素数 </TITLE>
</HEAD>
<BODY>
<center>
<font color=#0000ff> 素数寻找 </font> <form action="" method=post name="canshu">
<table>
<tr>
<td>
begin:
</td>
<td>
<input type="text" name="begin" value=3>
</td>
</tr>
<tr>
<td>
end:
</td>
<td>
<input type="text" name="end" value=100>
</td>
</tr>
<table>
<input type="submit" value=" find " onclick="findsushu(document.canshu.begin.value,document.canshu.end.value)" >
</form>
</center>
</BODY>
</HTML>
<script>
function findsushu( begin, end)
{ document.write(' <center>查找结果 </center> <br> <br>');
document.write('从'+begin+'到'+end+'的素数: <br> <br>');
var count=0;
begin=parseInt(begin,10);
end=parseInt(end,10)
for(var i=begin;i <=end;i++)
{
var flag=1;
for(var j=2;j <i;j++)
if(i%j==0)
{
flag=0; break;
}
if(flag==1)
{
count++;
document.write('   '+i);
if(count%10==0)
document.write(' <br>');
}
}
document.write(' <br> <br>素数个数总计:'+count);
}
</script>
<HEAD>
<TITLE>寻找素数 </TITLE>
</HEAD>
<BODY>
<center>
<font color=#0000ff> 素数寻找 </font> <form action="" method=post name="canshu">
<table>
<tr>
<td>
begin:
</td>
<td>
<input type="text" name="begin" value=3>
</td>
</tr>
<tr>
<td>
end:
</td>
<td>
<input type="text" name="end" value=100>
</td>
</tr>
<table>
<input type="submit" value=" find " onclick="findsushu(document.canshu.begin.value,document.canshu.end.value)" >
</form>
</center>
</BODY>
</HTML>
<script>
function findsushu( begin, end)
{ document.write(' <center>查找结果 </center> <br> <br>');
document.write('从'+begin+'到'+end+'的素数: <br> <br>');
var count=0;
begin=parseInt(begin,10);
end=parseInt(end,10)
for(var i=begin;i <=end;i++)
{
var flag=1;
for(var j=2;j <i;j++)
if(i%j==0)
{
flag=0; break;
}
if(flag==1)
{
count++;
document.write('   '+i);
if(count%10==0)
document.write(' <br>');
}
}
document.write(' <br> <br>素数个数总计:'+count);
}
</script>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货