我正在写一个应用程序与node.js和咖啡脚本和咖啡作为模板引擎。我有一个表单,我想在其中根据某些输入字段中是否有值来启用或禁用按钮。我想知道是否有像Sproutcore或Ember中那样的简单机制,只需一个绑定就可以了。我该怎么做呢?
发布于 2012-02-14 20:39:57
不,没有这种开箱即用的绑定。你要么实现像Ember,Knockout或Serenade.js这样的东西,要么自己滚动它。如果只有这一种形式,我只需要一个小脚本(下面的jQuery):
function validateForm() {
// Check if form fields are valid, return true if valid, false if not.
}
// Update the disabled attribute on a button inside "formId" anytime an input field is changed.
$("#formId").on("change", "input", function(event) {
$("#formId button").attr("disabled", !validateForm());
});https://stackoverflow.com/questions/9273831
复制相似问题