在jQuery中设置一个计数器 [英] Setting up a counter in jquery

查看:117
本文介绍了在jQuery中设置一个计数器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,其中包含基本的客户详细信息和信息.已经使用jquery来计算表单中字符的总数,现在我正在尝试实现计数器以查看填充表单所需的总时间,我的代码如下跟随

I have a form which includes basic client details and information.have used jquery to count total numbers of characters in the form and now I am trying to implement counter to see the total time taken to fill the form ,my codes are as follows

   <html>
        <title>  Employment Information
        </title>

      <style>
    table, td, th {
        border: 3px solid black;
    }

    td {
        padding: 15px;
    }
    </style>
    <script src="javascript/jquery-1.11.0.js"></script> 

 // codes for getting total number of charatecs typed //

    <script>
                    $('#form_3').on('submit', function(){
                         var count = 0;
                         $('input[type="text"], textarea', this).each(function(){
                         count += $(this).val().length;
                            });
                           alert("No of Characters Typed:" +count);
                           return true; // or true to submit form
                        });   
    </script>


        <body>
            <h4>MONTHLY INCOME AND COMBINED HOUSING EXPENSE INFORMATION</h4>


                <table border="1"  width="1300" height="150">
                  <tr>
                    <td>Gross monthly income</td>
                    <td>Borrower</td>
                    <td>Co-borrower</td>
                    <td>Total</td>
                    <td>Combined Monthly Housing Exp.</td>
                    <td>Present</td>
                    <td>Proposed</td>
                </tr>
                 <tr>
                 <td>Base EMPL income<</td>
                 <td>$::<input type="text" name="empl_income" id="empl_income"></td>
                 <td>$::<input type="text" name="co_borrower" ></td>
                 <td>$::<input type="text" name="base_empl_total"></td>
                    <td>Rent</td>
                    <td>$::<input type="text" name=""></td>
                     <td>$::<input type="text" name="years"></td>
                 </tr>
                   <tr>
                 <td>Overtime</td>
                 <td>$::<input type="text" name="overtime_borrower"></td>
                 <td>$::<input type="text" name="overtime_coborrower"></td>
                  <td>$::<input type="text" name="overtime_total"></td>
                 <td>Mortgaged</td>
                 <td>$::<input type="text" name="years"></td>
                  <td>$::<input type="text" name="years"></td>
                 </tr>
                 </table>

           <br>
           <br>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        <input type="submit" name="submit" value="SUBMIT" onclick="return validateform();">
           </form> 

        </body>
    </html>

如何与字符计数代码一起实现计时器??

How can I implement a time counter along with the character count codes.?

推荐答案

var timeStart;
var timeStop;

$(document).load(function() {
    timeStart = new Date();
});

$('#form_3').on('submit', function() {
    timeStop = Math.round((timeStart.getTime() - Date().getTime()) / 1000);
    console.debug('time taken from load till submit: ' + timeStop);
});

这篇关于在jQuery中设置一个计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆