0
我遇到了click
綁定問題。我試圖從Knockout網站運行一些示例代碼,這是行不通的。點擊次數沒有更新。我沒有在Firefox中收到任何javascript錯誤。有人可以幫忙嗎?點擊綁定不起作用
這是我的代碼:
<head runat="server">
<script type="text/javascript" src="/Scripts/jquery-1.6.4.js"></script>
<script type="text/javascript" src="/Scripts/jquery.tmpl.js"></script>
<script type="text/javascript" src="/Scripts/knockout-1.2.1.js"></script>
<script type="text/javascript">
var clickCounterViewModel = function() {
this.numberOfClicks = ko.observable(0);
this.registerClick = function() {
this.numberOfClicks(this.numberOfClicks() + 1);
}
this.hasClickedTooManyTimes = ko.dependentObservable(function() {
return this.numberOfClicks() >= 3;
}, this);
};
ko.applyBindings(new clickCounterViewModel());
</script>
</head>
<body>
<div>You've clicked <span data-bind="text: numberOfClicks"> </span> times</div>
<button data-bind="click: registerClick, enable: !hasClickedTooManyTimes()">Click me</button>
<div data-bind="visible: hasClickedTooManyTimes">
That's too many clicks! Please stop before you wear out your fingers.
<button data-bind="click: function() { numberOfClicks(0) }">Reset clicks</button>
</div>
</body>
哇......這讓我難住了一陣子。謝謝!!!這是淘汰賽的示例代碼...我希望他們已經指定! @ RP尼邁耶 – Hoppe