首页 >web前端 >html教程 >html实现阶乘,为什么不对,大神们帮我看看_html/css_WEB-ITnose

html实现阶乘,为什么不对,大神们帮我看看_html/css_WEB-ITnose

WBOY
WBOY原创
2016-06-24 11:53:251511浏览




项目3



<script> <br /> function js(){ <br /> var n = document.getElementById("form1").value; <br /> for (i=1,sum=0;i<=n;i++) <br /> { <br /> for(j=1,cj=1;j<=i;j++) <br /> {cj=cj*j;} <br /> sum=sum+cj; <br /> } <br /> document.getElementById("form2").value=sum <br /> } <br /> </script>
 
  
    
      
    
    
      
      
    
    
      
      
    
    
      
      
    
  

计算∑N!

输入整数N的值:

        
      
      
∑N!=

        
      
      

        
      
      

        
      
      





回复讨论(解决方案)

<html ><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>项目3</title></head><style type="text/css">.div{background-color:#339966;width:700px;height:250px;margin:0 auto;border:20px groove #4CBE4C;}.STYLE1 {color: #FFFFFF;font-weight: bold;font-size: 24px;}</style><body><script type="text/javascript"> function js(){ 	var n = parseInt(document.getElementById("N").value)||0;   var r=1; 	for (i=1;i<=n;i++){r*=i;}	document.getElementById("sum").value=r }</script><div class="div"> <form id="form3" name="form3" method="post" action="">  <table width="700" border="0" align="center">    <tr>      <td height="50" colspan="2"><p align="center" class="STYLE1" >计算&#8721;N!</p></td>    </tr>    <tr>      <td height="50" class="STYLE1"><div align="center">输入整数N的值:</div></td>      <td height="50">        <label>          <input type="text" name="N" id="N" />          </label>    </td>    </tr>    <tr>      <td height="50" class="STYLE1"><div align="center">&#8721;N!=</div></td>      <td height="50">        <label>          <input type="text" name="sum" id="sum" />          </label>    </td>    </tr>    <tr>      <td height="50">        <label>        <div align="center">          <input type="submit" name="Submit" value="计算∑N!"  onClick="js();return false;"/>        </div>        </label></td>      <td height="50">        <label>          <div align="center">            <input type="reset" name="Submit2" value="清空" />          </div>        </label>    </td>    </tr>  </table>      </form>  </div></body></html>

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn