【问题标题】:MeteorJS: How to get value of an input textMeteorJS:如何获取输入文本的值
【发布时间】:2015-06-17 19:24:53
【问题描述】:

我有这个代码:

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 的值?我尝试了事件变量,但它在按钮中受到限制。有什么想法吗?

【问题讨论】:

    标签: javascript node.js meteor coffeescript pug


    【解决方案1】:

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

    '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
    

    【讨论】:

      猜你喜欢
      • 2015-06-18
      • 1970-01-01
      • 2013-07-11
      • 2015-11-12
      • 1970-01-01
      • 2012-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多