看到这个小提琴:http: //jsfiddle.net/BxvVp/11/
我创建了一个视图模型,该模型具有用div
页面上的一些隐藏内容替换内容的功能。完成后,text
绑定似乎已处理,但click
绑定未处理。
难道我做错了什么?
html:
<h4>Clicking the anchor created by clicking 'Summarize' should cause an alert, but doesn't.</h4>
<a href="#" data-bind="click: summarize">Summarize</a>
<div id="plot1"></div>
<div id="summary1" style="display:none;"> <a data-bind="text: 'anchor-text-replaced', click: function(data, event) { alert('anchor clicked!'); }" href="#">anchor-text</a>
</div>
<hr />
<h4>Clicking this anchor causes the alert as exptected.</h4>
<div id="plot2"></div>
<div id="summary2">
<a data-bind="text: 'anchor-text-replaced', click: function(data, event) { alert('anchor clicked!'); }" href="#">anchor-text</a>
</div>
javascript:
var ViewModel = function () {
var self = this;
self.summarize = function () {
$("#plot1").html($("#summary1").html());
};
};
ko.applyBindings(new ViewModel());