我的流星项目中有一些坏掉的按钮。我有一种感觉,如果一个固定,所有都将被修复,所以这是最简单的一个。问题是,每次按下更新按钮,浏览器都会刷新而不是仅仅更改数据。我使用全局变量,因此我可以轻松地重用从下拉菜单中收集的数据。
在我的HTML中:
<template name="earning">
<div class="panel panel-success">
<div class="panel-body">
<form>
<div class="form-group">
<select class="btn btn-primary dropdown-toggle" data-toggle="dropdown" id="period">
<option> Select a frequency.. </option>
<option value="weekly">Weekly</option>
<option value="monthly">Monthly</option>
<option value="yearly">Yearly</option>
</select>
</div>
<div class="form-group">
<label for="earning"> Income:</label>
<input type="text" class="form-control" name="earning" id="earning" placeholder="Enter Income..." >
</div>
<button type="submit" class="btn btn-success"> Update </button>
</form>
</div>
</div>
</template>
然后在我的js中:
Template.earning.events({
"change #period": function(event, template) {
window.per = template.$("#period").val();
console.log(window.per);
},
"submit form": function(event, template) {
var pearn = parseInt(event.target.earning.value);
var period = window.per;
console.log(income);
if(period === 'monthly'){
income = pearn*12;
}
else if(period === 'weekly'){
income = pearn*52;
}
else
income = period;
console.log(income);
inc = {Period: period, Income: pearn}; }});
我需要帮助吗