JS提交form -- horoscope feature小结
horoscope做了有1周了,第一次的方案是用meta来控制输出的class,利用js来读取class的值判断是哪个layout,这样的坏处就是无法添加更多的layout。被否决了。
接着的方案有2种,1种是用SlotGroup + Slot + InfoPath;
还有就是就是纯粹的Slot + InfoPath。
纯粹的InfoPath其实没啥好讲的,就是做InfoPath,把原来的library变成feature而已,太死,没啥意思。
现在来分析一下SlotGroup + Slot + InfoPath。
在SlotGroup中要做到无论子节点Slot是什么样的form,它都能读取到。
在SlotGroup中实现是比较简单的,只需要把form触发的submit给preventDefault掉
form.submit(function(event){
...
event.preventDefault();
...
});
...
event.preventDefault();
...
});
这是jQuery的原文

jQuery.fn["submit"] = function(fn) {
/// <summary>
/// 1: submit() - Triggers the submit event of each matched element.
/// 2: submit(fn) - Binds a function to the submit event of each matched element.
/// </summary>
/// <param name="fn" type="Function">The function to execute.</param>
/// <returns type="jQuery" />
return fn ? this.bind("submit", fn) : this.trigger(name);
};
/// <summary>
/// 1: submit() - Triggers the submit event of each matched element.
/// 2: submit(fn) - Binds a function to the submit event of each matched element.
/// </summary>
/// <param name="fn" type="Function">The function to execute.</param>
/// <returns type="jQuery" />
return fn ? this.bind("submit", fn) : this.trigger(name);
};
但是当我用select.change()
{
form.submit();
}
竟然没触发submit,很郁闷以为是拼写错误,检查了许久。郁闷的时候接着试了一下form.trigger("submit") ;竟然成功了。
其中的原因还没有细看,先标记一下,等项目没那么紧了,再把这篇补齐。