如何在事件中使用每个输入值?希望我的下面代码能很好地解释你。
How can one use each input values in events? Hope my below code will explain you well.
HTML:
<template name="UpdateAge"> {{#each Name}} <div data-action="showPrompt"> <div> Some content </div> <div> <div> Some content </div> </div> <div> Name : {{name}} Age : <input type="text" name="age" value="{{age}}"/> //I need to access age values in event </div> </div> {{/each}} <template>JS:
Template.UpdateAge.events({ 'click [data-action="showPrompt"]': function (event, template) { console.log(event.target.age.value); // TypeError: event.target.age.value is undefined } });我不知道我的方法是否适合将参数值传递给事件欢迎提出建议。
I dont know whether my approach is good for passing parameter values to events so suggestions are welcome.
推荐答案您使用的符号仅对表单元素和事件有效.target是表单元素。
the notation you are using is valid only for form elements and when event.target IS a form element.
event.target.age.valueevent.target 是发生事件的元素, event.currentTarget 是附加了该事件的元素事件处理程序
event.target is the element where the event occurred, event.currentTarget is the element which has attached the event handler
如果用表单替换 div 并且用 currentTarget 替换目标然后它将起作用
if you replace div with form and replace target with currentTarget then it will work
event.currentTarget.age.value这里是小提琴使用你的代码
更多推荐
event.target在事件中未定义
发布评论