js for循环问题...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function changeItem(){
var start=document.getElementById("per_start").value;
var end=document.getElementById("per_end").value;
var type=document.getElementById("sce_type").value;
var count=0;
if(!isNaN(start) && !isNaN(end)){
var amount=0;
var odd=0;
var even=0;
for(var i=start;i<=end;i++){
amount++;
if(i%2==0){
even++;
}else if(i%2!=0){
odd++;
}
}
if(type=="0"){
count=amount;
}else if(type=="1"){
count=odd;
}else if(type=="2"){
count=even;
}
}
document.getElementById("count").value=count;
}
</script>
</head>
<body>
起止期:<input type="text" size="6" id="per_start" value="0" onchange="changeItem();" />
<input type="text" size="6" id="per_end" value="0" onchange="changeItem();" /><br /><br />
类 型:
<select name="sce_type" id="sce_type" onchange="changeItem();">
<option value="0">连期</option>
<option value="1">奇连期</option>
<option value="2">偶连期</option>
</select><br /><br />
期 数:
<input type="text" size="6" id="count" value="0" />
</body>
</html>
页面如图:
根据起止期和类型获取期数,当起止期分别为1,15,类型为连期时,结果为15,当起期为2到9,止期>10,<20时,结果为0,没有进入for循环,这是为什么?
------解决方案--------------------lz莫有错误啊
------解决方案--------------------先看一下进了if了没
------解决方案--------------------
JScript code
if(!isNaN(start) && !isNaN(end)){
var amount=0;
var odd=0;
var even=0;
//alert(start+'^'+end);
//alert(end-start+'*');
for(var i=start;end-i>0;i++){
//alert(i);
amount++;
if(i%2==0){
even++;
}else if(i%2!=0){
odd++;
}
}