【发布时间】:2015-10-04 12:21:42
【问题描述】:
我有一个简单的表单,有两个输入:“title”和_“description”,还有两个按钮:“save”(稍后保存)和“submit”。对于两者,我都想获取表单字段的值并相应地插入/更新我的集合。
<template name="NewScenarioForm">
<form id="newScenarioForm" >
<textarea type="text" id="title" name="title" rows="1" cols="75" placeholder="Type to add a title"></textarea><br/>
<textarea type="text" id="description" name="description" rows="4" cols="100" placeholder="Type to add a description" ></textarea><br/>
<input type="submit" id="saveScenarioButton" name="action" title="Save Scenario" value="Save" />
<input type="submit" id="submitScenarioButton" name="action" title="Submit for approval" value="Submit" />
</form>
</template>
现在我正在检测这样的事件:
"click #saveScenarioButton": function(event, template) {
event.preventDefault();
var title = template.find("#title").value;
var description = template.find("#description").value;
...
//Do stuff with this information to persist information
Meteor.call("saveScenario", title, description);
....
}
我需要为另一个按钮重复整个功能。我想检测事件并确定按下了哪个按钮。
我一直在努力处理如下事件处理程序:
"submit #newScenarioForm": function(event) {
但是我不知道如何确定单击的按钮,因为我无法确定事件属性。如果我想在我的事件处理程序中使用表单 ID 而不是每个按钮的 ID(或者更聪明的方法来完全解决这个问题?),有没有办法确定按钮?
【问题讨论】:
标签: javascript forms meteor