【问题标题】:Is there a way to keep track of javascript hits?有没有办法跟踪 javascript 点击?
【发布时间】:2010-06-02 19:22:55
【问题描述】:

我正在填充基于 javascript 函数的表。我想将输入的数据限制为 2,然后隐藏表格。有没有办法跟踪 javascript 代码被点击的次数?

function addNewRow() {
    $('#displayInjuryTable tr:last').after('<tr><td style="font-size:smaller;" class="name"></td><td style="font-size:smaller;" class="address"></td></tr>');
    var $tr = $('#displayInjuryTable tr:last');
    var propertyCondition = $('#txtInjuryAddress').val();


    $tr.find('.name').text($('#txtInjuryName').val());
    if (propertyCondition != "") {
        $tr.find('.address').text($('#txtInjuryAddress').val() + ', ' + $('#txtInjuryCity').val() + ' ' + $('#txtInjuryState').val() + ' ' + $('#txtInjuryZip').val());
 }

【问题讨论】:

    标签: .net asp.net javascript html


    【解决方案1】:
    var someCounter = 0
    
    function addNewRow() {
      if(someCounter>1) {
        return
      }   
      someCounter++
     ...your code...
    }
    

    【讨论】:

    • 您需要根据 OP 规范在“返回”之前隐藏表格。
    【解决方案2】:
    var addNewRow = (function(){
        var count = 0;
        return function(){
            if (++count === 2) {
                //hide feature 
                return;
            }
            ... // your code here
        }
    })();
    

    【讨论】:

      猜你喜欢
      • 2011-04-08
      • 1970-01-01
      • 2019-09-08
      • 2012-07-07
      • 2017-07-23
      • 2012-06-14
      • 1970-01-01
      • 1970-01-01
      • 2010-12-24
      相关资源
      最近更新 更多