gpt4 book ai didi

javascript - Backbone-forms.js - 如何在 github "docs"示例中呈现提交按钮

转载 作者:搜寻专家 更新时间:2023-10-31 08:08:00 24 4
gpt4 key购买 nike

这是 Backbone 形式的代码。现在,我想呈现一个提交按钮来验证我的文本字段和东西,这是记录在案的,除了如何将该提交按钮放入dom中。随意投反对票,无论如何,在我看来,这对于菜鸟来说很难理解

(function($) {
var cities = {
'UK': ['London', 'Manchester', 'Brighton', 'Bristol'],
'USA': ['Washington DC', 'Los Angeles', 'Austin', 'New York']
};

//The form
var form1 = new Backbone.Form({
schema: {
country: { type: 'Select', options: ['UK', 'USA'] },
city: { type: 'Select', options: cities.UK },
message: { type: 'Text'}
}
}).render();

form1.on('country:change', function(form1, countryEditor) {
var country = countryEditor.getValue(),
newOptions = cities[country];
form1.fields.city.editor.setOptions(newOptions);

});

//Add it to the page
$('body').append(form1.el);
})(jQuery);

最佳答案

我的 friend ,你需要使用 BBF 模板!

虽然附加它是一种实现方式,但您应该真正坚持 BBF 实现按钮的方式。您可以创建不同的模板或在必要时重新使用它们,您可以从这里向表单添加属性等。希望这有助于...

检查工作演示: http://jsfiddle.net/c5QHr/116/

$(function() {

//// Set the template ----------------------------->
Backbone.Form.setTemplates({
customTemplate: '<form id="your-form-id">{{fieldsets}}<input id="your-form-cancel" type="reset" value="cancel" name="reset" /><input type="submit" value="submit" name="submit" />'

});

var cities = {
'UK': ['London', 'Manchester', 'Brighton', 'Bristol'],
'USA': ['Washington DC', 'Los Angeles', 'Austin', 'New York']
};

//The form
var form = new Backbone.Form({
//// Use the template ----------------------------->
template: 'customTemplate',
schema: {
country: { type: 'Select', options: ['UK', 'USA'] },
city: { type: 'Select', options: cities.UK }
}
}).render();

form.on('country:change', function(form, countryEditor) {
var country = countryEditor.getValue(),
newOptions = cities[country];

form.fields.city.editor.setOptions(newOptions);
});

//Add it to the page
$('body').append(form.el);

////Do something with the buttons ----------------------------->

$("#your-form-id").submit(function(){alert('BBF Form was submitted!'); return false;});
$("#your-form-cancel").on('click',function(){alert('BBF Form was cancelled!'); });

});

关于javascript - Backbone-forms.js - 如何在 github "docs"示例中呈现提交按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14589309/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com