我需要客户端能够将值输入到 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" />
谢谢你的帮助!