【问题标题】:MeteorJS: Change value of input textMeteorJS:更改输入文本的值
【发布时间】:2015-06-18 05:03:39
【问题描述】:

我有这个代码

product.jade

 a#home(href="{{pathFor 'home'}}") Home
 input#qty.form-control(type="text", value="1", name="qty")

product.coffee

Template['product'].events
    'click #home': (e, template) ->
       text = template.find("#qty")
       ???
       return

如何在每次点击主页时将 qty 的值设置为 5?我尝试使用 text.value("5") 但发生错误

未捕获的类型错误:字符串不是函数。

有什么想法吗?

【问题讨论】:

  • 文件名为product.jade,但模板名称为header?这很好,但我只想确定哪个模板包含哪些元素。

标签: javascript node.js meteor coffeescript pug


【解决方案1】:

试试这个:

Template.product.events
  'click #home': ->
    $('#qty').val 5

请记住,ID 只应在页面上出现一次,因此 template.find 在这里并不是必需的。

【讨论】:

    【解决方案2】:

    试试这个:

    Template.product.events
      'click #home': (e, template) ->
        template.$('#qty').val 5
    

    或者这个:

    Template.product.events
      'click #home': (e) ->
        $(e.currentTarget).parent().find('#qty').val 5
    

    【讨论】:

      猜你喜欢
      • 2015-06-17
      • 1970-01-01
      • 2011-08-08
      • 2020-08-31
      • 2017-10-07
      • 2012-12-14
      • 1970-01-01
      • 2016-04-25
      • 2013-02-01
      相关资源
      最近更新 更多