Bootstrap模态表单在使用knockout的submit绑定时无法提交。
Bootstrap模态表单在使用knockout的submit绑定时无法提交。
我在这里有一个jsFiddle的例子:http://jsfiddle.net/vsZhg/
我正在一个Bootstrap模态框内构建一个表单。问题是,除非用户点击提交按钮,否则knockout的提交绑定不会执行。我怀疑是Bootstrap阻止了knockout的绑定执行,但我不知道该如何解决这个问题。
如果你按下回车键,模态对话框会关闭,并且绑定函数不会执行(结果无法发送数据)。但是,如果你点击提交按钮,绑定会按预期执行。
以下是相关的代码:
脚本:
function ArticleViewModel() { var self = this; self.SendArticleName = ko.observable(''); self.SendArticleEmail = ko.observable(''); self.SendArticle = function() { $.ajax('http://example.com', { data: ko.toJSON({ name: self.SendArticleName, email: self.SendArticleEmail }), type: "post", contentType: "application/json", success: function(result) { $('#share-modal').modal('hide'); } }); }; } var articleViewModel = new ArticleViewModel(); ko.applyBindings(articleViewModel);
HTML:
分享
分享这篇文章