天天看點

JS求和執行個體

2015-11-19 11:05:06

存在問題:

如何實作JS的加和

解決方案:

代碼如下

<script type="text/javascript">       
      function sumH() {
            var sunHezhi = ;
            var SXZ = document.getElementById("TextBox1").value;  //textbox取值
            for (var i = ; i < SXZ; i++) {
                sunHezhi +=  / (i * i);
                sunHezhi = parseFloat(sunHezhi);  //數字轉換
            }
            alert(sunHezhi.toFixed());
         }
    </script>
    <asp:Button ID="Button1" runat="server" OnClientClick="sumH()" Text="Button" />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>