【发布时间】:2015-11-08 17:21:57
【问题描述】:
为什么点击事件后这段代码的属性没有显示?
属性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>
【问题讨论】:
-
这属于特定的上下文,你在内部函数中使用它,所以它在那里被覆盖
标签: javascript jquery oop properties undefined