我正在练习一个小项目 . 根据鼠标移动,必须启动或停止秒表 . 即,一旦鼠标在里面,然后启动秒表,否则停止 . 可能吗?
我的代码:aspx页面
<div id="Divn1" onmousemove="MyNewFunction(event)" onmouseout="ClearCoor()" style="width:99%; height:99%; border:solid;background-color:white; position:absolute;">
<p id="Demo1"></p>
<asp:Label ID="Label2" runat="server" Font-Size="XX-Large"></asp:Label>
<div id="Divn2" style="width:50px;height:50px;border-radius:50%;background-color:brown; position:absolute; top:45%; margin-left:47%;">
</div>
<asp:scriptmanager ID="Scriptmanager1" runat="server"></asp:scriptmanager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Font-Size="XX-Large"></asp:Label>
<asp:Timer ID="tm1" Interval="1000" runat="server" ontick="tm1_Tick" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="tm1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
</div>
然后是aspx.cs
public static Stopwatch sw;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
sw = new Stopwatch();
sw.Start();
}
}
protected void tm1_Tick(object sender, EventArgs e)
{
long milsecs = sw.Elapsed.Milliseconds;
if (Label2.Text.Trim().Length > 0)
{
Label1.Text = DateTime.Now.ToString("00:ff");
}
sw.Stop();
//Label1.Visible = false;
}
谢谢