看到这个问题.除非在单击子元素时答案返回子元素,即在绑定div的情况下.
<div id="parent" data-bind="click: log">Parent Div<div id="child">Child</div></div>
<script>
var ViewModel = function() {
this.log = function(data, event) {
console.log("you clicked " + event.target.id);
}
};
ko.applyBindings(new ViewModel());
</script>
Run Code Online (Sandbox Code Playgroud)
看到这个小提琴
我想获取click事件绑定的原始元素.有什么建议?
我正在使用bind
我的视图中的参数调用该函数:
<span data-bind="click: modifyByOne.bind($data, 'plus')"></span>
Run Code Online (Sandbox Code Playgroud)
根据这个答案我event
通过这样做获得对象:
self.modifyByOne = function(type){
var span = $(event.currentTarget);
};
Run Code Online (Sandbox Code Playgroud)
在Chrome中一切正常,但在Firefox中我收到以下控制台错误:
事件未定义
我怎样才能让它在Firefox中运行?淘汰文档没有提供太多答案.