javascript 淘汰赛js点击绑定不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25580783/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 04:41:19  来源:igfitidea点击:

knockout js click binding not working

javascriptjqueryknockout.jsclick

提问by kumar

I used the example of knockout jsand its not working. I don't know why click event is not firing.

我使用了 的示例,但knockout js它不起作用。我不知道为什么点击事件没有触发。

HTML:

HTML:

<div>
    You've clicked <span data-bind="text: numberOfClicks"></span> times
    <button data-bind="click: incrementClickCounter">Click me</button>
</div>

Javascript:

Javascript:

<script type="text/javascript">
    var viewModel = {
    numberOfClicks : ko.observable(0),
    incrementClickCounter : function() {
    alert("hi im click");
    var previousCount = this.numberOfClicks();
    this.numberOfClicks(previousCount + 1);
     }
    };
</script>

回答by Prashant Tapase

Try this code Go Through link

试试这个代码通过链接

HTML:

HTML:

<div>
    You've clicked <span data-bind="text: numberOfClicks"></span> times
    <button data-bind="click: incrementClickCounter">Click me</button>
</div>

Javascript:

Javascript:

<script src="~/Scripts/jquery-2.1.1.js"></script>
<script src="~/Scripts/knockout-3.2.0.js"></script>
<script type="text/javascript">
    var viewModel = {
    numberOfClicks : ko.observable(0),
    incrementClickCounter : function() {
    alert("hi im click");
    var previousCount = this.numberOfClicks();
    this.numberOfClicks(previousCount + 1);
     }
    };

ko.applyBindings(new viewModel());
</script>