gpt4 book ai didi

javascript - meteor JS : How to get value of an input text

转载 作者:行者123 更新时间:2023-11-30 16:56:47 25 4
gpt4 key购买 nike

我有这个代码:

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

最佳答案

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

'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

关于javascript - meteor JS : How to get value of an input text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29589154/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com