0

我需要客户端能够将值输入到 asp TextBox 中,询问他们花费在这些活动上的小时数。他们输入的数字在 javascript 中运行。我很难将这些值输入 javascript。然后让它在按钮单击时运行。谢谢你的帮助。这是我到目前为止所得到的:

<script runat="server">

    void btn_Click(object sender, EventArgs e)
    {
        double work = double.Parse(TextBox1.Text);
        double eat = double.Parse(TextBox2.Text);
        double commute = double.Parse(TextBox3.Text);
        double tv = double.Parse(TextBox4.Text);
        double sleep = double.Parse(TextBox5.Text);
        double total = work + eat + commute + tv + sleep;
        if (total > 24)
        {
            lblmsg.Text = code();
        }
    }
    string code()
    {
        return "Warning: There are only 24 hours in a day!";
    }
</script>

Java脚本:

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
        google.load("visualization", "1", { packages: ["corechart"] });
        google.setOnLoadCallback(drawChart);
        function drawChart() {
            var work = document.getElementById('<%=TextBox1.ClientID%>').value;
            var eat = document.getElementById('<%=TextBox2.ClientID%>').value;
            var commute = document.getElementById('<%=TextBox3.ClientID%>').value;
            var tv = document.getElementById('<%=TextBox4.ClientID%>').value;
            var sleep = document.getElementById('<%=TextBox5.ClientID%>').value;
            var data = google.visualization.arrayToDataTable([
              ['Task', 'Hours per Day'],
              ['Work', work],
              ['Eat', eat],
              ['Commute', commute],
              ['Watch TV', tv],
              ['Sleep', sleep]
            ]);

            var options = {
                title: 'My Daily Activities',
                is3D: true,
            };

            var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
            chart.draw(data, options);
        }

    </script>

文本框和按钮:

Work:<asp:TextBox ID="TextBox1" runat="server" Text="11"/><asp:Label ID="lblmsg" runat="server" color="red" BackColor="red" Font-Size="XX-Large"/><br />
          Eat:<asp:TextBox ID="TextBox2" runat="server" text="2"/><br />
          Commute:<asp:TextBox ID="TextBox3" runat="server" text="2"/><br />
          Watch TV:<asp:TextBox ID="TextBox4" runat="server" text="2"/><br />
          Sleep:<asp:TextBox ID="TextBox5" runat="server" text="7"/><br />
          <asp:Button ID="btn" runat="server" Text="COMPUTE TIME" OnClick="btn_Click" />

谢谢你的帮助!

4

1 回答 1

0

我想你在这里混合了苹果和橘子。您不需要 ASP.NET 或任何其他服务器端语言来进行基本的客户端计算。无论如何,仅 jQuery 就可以使用简单的 HTML 文本框来做到这一点。只需学习使用 jQueryval()就足够了。

于 2013-11-02T20:17:20.583 回答