MeteorJS:如何获取输入文本的值

时间:2015-04-12 11:53:03

标签: javascript node.js meteor coffeescript pug

我有这段代码:

product.jade

template(name="product")
    label(for="qty") Qty:
    input#qty.form-control(type="text", value="1", name="qty")
    button.btn.btn-default.addcart Add to Cart

product.coffee

Template['product'].events
  'click .addcart': (event, template) ->
    ????

如何获取输入文本qty的值?我尝试了事件变量,但它在按钮中有限。有什么想法吗?

1 个答案:

答案 0 :(得分:2)

考虑到您的代码,您可以获得如下值:

'click .addcart': (event, template) ->
    qty = template.find('#qty').value;

您可以在此处查看有关template.find()的文档。

但如果您在<form>上有提交活动,也可以这样做:

'submit .your-form': (event, template) -> 
    qty = event.target.qty.value //qty = name of the field