有没有办法跟踪javascript命中?

时间:2010-06-02 19:22:55

标签: .net asp.net javascript html

我正在基于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());
 }

2 个答案:

答案 0 :(得分:3)

var someCounter = 0

function addNewRow() {
  if(someCounter>1) {
    return
  }   
  someCounter++
 ...your code...
}

答案 1 :(得分:0)

var addNewRow = (function(){
    var count = 0;
    return function(){
        if (++count === 2) {
            //hide feature 
            return;
        }
        ... // your code here
    }
})();