第一次真正意思上写的js

<script type="text/javascript">
        
          var totalItem=13;
           var strTmp=new Array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1);
              var fSum= new Array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1);
               var strOptionID=new Array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1);
               var strValue=new Array(-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2);
            function checkMaxlength(obj,evt,maxLength)  
            {
                var event = window.event|| evt;
                if(event.keyCode != 8)
                {
                    if(obj.value.length > maxLength)
                    {
                        obj.value = obj.value.substring(0,maxLength);
                        evt.returnValue = false;
                    }
                }
                
                var lbl = document.getElementById("ctl00_ContentPlaceHolder1_lblDescriptionLenth");
                
                 lbl.innerHTML = maxLength - (obj.value.length) ;
            }          
            
            function checkIsSelected()
            {
               var lab=document.getElementById("ctl00_ContentPlaceHolder1_labTotalNum");
                if(lab.innerHTML=="")
                {
                  var litMessage=document.getElementById("ctl00_ContentPlaceHolder1_litMessage");
                   litMessage.innerHTML="<div class=\"error\"> You need to select at least one opition to rate.</div>";
                  setTimeout("window.location.hash='top1'",500);
                   return false;
                 
                }
              else
              {
                       var c=document.getElementsByName("ctl00$ContentPlaceHolder1$radioListExperience");
                       var result=-2;
                      if (c.length>0)
                      {
                        for    (i=0;i<c.length;i++)
                        {
                    
                           if(c[i].checked==true)
                           {
                             result=1;
                             return true;
                             
                             break;
                           }
                        }
                      }
                      if(result<0)
                      {
                      var litMessage=document.getElementById("ctl00_ContentPlaceHolder1_litMessage");
                   litMessage.innerHTML="<div class=\"error\"> Please select the Experience with radio! </div>";
                  setTimeout("window.location.hash='top1'",500);
                       return false;
                      }
                }      
                     
            }
            
            function checkRadioIsChecked()
            {
              var c=document.getElementsByName("ctl00$ContentPlaceHolder1$radioListExperience");
              
              if (c.length>0)
              {
                for    (i=0;i<c.length;i++)
                {
                   if(c[i].checked==true)
                   {
                     return true;
                     break;
                   }
                }
                return false;
              }
            }
            
            function ItemCount(itemName,value,ModleName,ModleId)
            {    
             var sum=0;
               var fCount=0;
               var TepName="";
               var TepId="";
               var TepValue="";
              for(var i=0;i<totalItem;i++)
              {       
                   if(itemName.toString()==("gp"+i.toString()))
                   {
                     fSum[i]=value;   
                     strTmp[i]=ModleName;  
                     strOptionID[i]=ModleId;
                     if(value==-1)
                     {
                       strValue[i]=0;
                      }
                      else
                      {
                        strValue[i]=value;
                      }
                     
                   }     
              }
              for(var i=0;i<totalItem;i++)
              {
                if(fSum[i]!=-1)
                {
                  sum=sum+fSum[i];
                  fCount=fCount+1;
                }      
                if(strValue[i]!=-2)
                {
                  TepName=TepName+strTmp[i]+"^";
                  TepId=TepId+strOptionID[i]+"^";
                  TepValue=TepValue+strValue[i]+ "^";
                }
              }
              if(sum!=0)
              {
                var result=(parseFloat(sum)/parseFloat(fCount));
                var lab=document.getElementById("ctl00_ContentPlaceHolder1_labTotalNum");
                var hidTepId=document.getElementById("<%=hidTepId.ClientID %>");
                var hidTepName=document.getElementById("<%=hidTemName.ClientID %>");
                var hidTepValue=document.getElementById("<%=hidTemValue.ClientID  %>");
                hidTepId.value=TepId;
                hidTepName.value=TepName;
                hidTepValue.value=TepValue;
                lab.innerHTML=to2bits(result);
                
              }
              else
              {
                 var lab=document.getElementById("ctl00_ContentPlaceHolder1_labTotalNum");
                 var result=-1;
                lab.innerHTML=" ";
                for(var i=0;i<totalItem;i++)
                {
                  if(strValue[i]!=-2)
                  {
                    result=1;
                    break;
                  }
                }
                if(result>0)
                {
                  var hidTepId=document.getElementById("<%=hidTepId.ClientID %>");
                var hidTepName=document.getElementById("<%=hidTemName.ClientID %>");
                var hidTepValue=document.getElementById("<%=hidTemValue.ClientID  %>");
                hidTepId.value=TepId;
                hidTepName.value=TepName;
                hidTepValue.value=TepValue;
                }
                
              }
              
            }

function to2bits(flt) {
if(parseFloat(flt) == flt)
return Math.round(flt * 100) / 100;
// 到4位小数, return Math.round(flt * 10000) / 10000;
else
return 0;
}             
    </script>
posted on 2009-07-23 15:41  prayforsmile  阅读(247)  评论(0编辑  收藏  举报