event.target在事件中未定义

编程入门 行业动态 更新时间:2024-10-22 13:37:12
本文介绍了event.target在事件中未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何在事件中使用每个输入值?希望我的下面代码能很好地解释你。

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.value

event.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在事件中未定义

本文发布于:2023-11-28 06:55:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641371.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:未定义   事件中   event   target

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!