如何使用Javascript计算asp:repeater文本框中的响应时间?

时间:2016-09-28 06:15:49

标签: javascript asp.net timer

我有一个带有asp:repeater的多个文本框,我想计算在文本框出现后在该文本框中键入文本所花费的时间。我尝试了onblur和onfocus事件,但没有正常工作,因为它在计算前一个文本框的时间时占用了下一个文本框的焦点时间。 我的转发器代码如下

<asp:Repeater ID="rpt1" runat="server">
<asp:TextBox ID="txt1" autocomplete="off" EnableViewState="true"     onfocus="f1(this);" onblur="f2(this);"  runat="server"></asp:TextBox>
</asp:Repeater>

和这样的javascript代码

        function f1(e) {
            var onFocusTextTime = new Date().getTime();
            alert("onFocus:" + onFocusTextTime);
            return onFocusTextTime;
        }
        function f2(e) {
            var responceForAnswer = "";
            var diff_result = "";
            var onBlurTextTime = new Date().getTime();
            alert("onBlur:" + onBlurTextTime);
            var onFocusTextTime = f1();
            diff_result = onFocusTextTime - onBlurTextTime;
            alert("diff_result:" + diff_result);
            var hours = diff_result / (1000 * 60 * 60);
            var absoluteHours = Math.floor(hours);
            var h = absoluteHours > 9 ? absoluteHours : '0' + absoluteHours;
            var minutes = (hours - absoluteHours) * 60;
            var absoluteMinutes = Math.floor(minutes);
            var m = absoluteMinutes > 9 ? absoluteMinutes : '0' + absoluteMinutes;
            var seconds = (minutes - absoluteMinutes) * 60;
            var absoluteSeconds = Math.floor(seconds);
            var s = absoluteSeconds > 9 ? absoluteSeconds : '0' + absoluteSeconds;
            responceForAnswer = h + ':' + m + ':' + s;
            alert("responceForAnswer:" + responceForAnswer);

        }

1 个答案:

答案 0 :(得分:0)

我刚刚按照以下方式更改了我的代码,并且其工作

 var button = document.getElementById("hide");
 var p = document.getElementById("pb"); 
 function hide(){
   p.classList.add("hide");             
   alert("The paragraph gone!");
 }