为什么这个jQuery OOP属性变得不确定?

时间:2015-08-15 17:17:35

标签: javascript jquery oop properties undefined

为什么在点击事件后没有显示此代码的属性?

属性this.ContainerId在输入this.ShoutCount方法时变为未定义。

谢谢。



var table = function (containerId) {
  this.ContainerId = containerId;
  
  this.ShoutCount = function (totalC) {
        var label = $("#" + this.ContainerId + " .result").text();
        alert(totalC + " " + label);
  }
  this.ClickCount = function (sc) {
    $("#" + this.ContainerId + " .showTotalCount").click(function () {
      sc($(this).text());
    });
  }
  this.ClickCount(this.ShoutCount);
}

var t = new table("user-tab-pagination");

<div id="user-tab-pagination">
  <div class="search-count"><span class="showTotalCount">100</span> <span class="result">Result(s)</span></div>
</div>
&#13;
&#13;
&#13;

0 个答案:

没有答案