Javascript 主干表单提交刷新Chrome页面
与此类似的问题:。 提交我的引导模式表单失败,并在Chrome中刷新页面。我理解链接中的解决方案,但我不知道如何使其适用于引导表单。有什么帮助吗Javascript 主干表单提交刷新Chrome页面,javascript,jquery,twitter-bootstrap,backbone.js,Javascript,Jquery,Twitter Bootstrap,Backbone.js,与此类似的问题:。 提交我的引导模式表单失败,并在Chrome中刷新页面。我理解链接中的解决方案,但我不知道如何使其适用于引导表单。有什么帮助吗 window.FormPopup = Backbone.View.extend({ template: _.template($('#popup-template').html()), events: { "click .sector-label" : "edit", "keypress .sector-label-edit inpu
window.FormPopup = Backbone.View.extend({
template: _.template($('#popup-template').html()),
events: {
"click .sector-label" : "edit",
"keypress .sector-label-edit input" : "setLabel"
},
render: function() {
var view = this;
this.$el.html(this.template(this.model.toJSON()));
this.$el.modal({
backdrop: false
});
this.$el.on("hidden", function() {
view.remove();
});
this.$el.find("form").submit(function() {
$(this).find("input:text").each(function() {
var label = $(this).val();
if (label.length > 0)
view.model.addChild(label);
});
view.$el.modal("hide");
});
},
edit: function() {
this.$el.addClass("edit");
this.$el.find(".sector-label-edit input").focus();
},
setLabel: function(e) {
if (e.keyCode != 13)
return;
var newLabel = this.$el.find(".sector-label-edit input").val();
this.model.set("label", newLabel);
this.$el.find(".sector-label h3").html(newLabel);
this.$el.removeClass("edit");
},
});
您是否使用AJAX提交表单?拯救一个模型?您需要阻止默认浏览器提交并自行处理。另外,为什么不在事件哈希中绑定表单提交?签出以防止默认提交事件。