简体   繁体   English

从 jQuery 元素中检索“e.target”

[英]retrieve `e.target` from jQuery element

I have a jquery element.我有一个 jquery 元素。 The updateHandler function expects a DOM element with e.target.name and e.target.value updateHandler function 需要一个带有e.target.namee.target.value的 DOM 元素

How can I pass the e fetched with jQuery to updateHandler function with e.target / e.value ?如何将使用 jQuery 获取的e传递给使用e.target / e.value 的updateHandler e.value

let e = $('[name="amount"]')
// or
// let e = document.getElementsByName('amount') //

// modify the value of e and pass it to below
updateHandler(e[0]) // This function expects e.target

The error is e.target is undefined.错误是e.target未定义。 In both cases using jQuery($) or document.xxx .在这两种情况下都使用jQuery($)document.xxx

SOLUTION解决方案

As per @Ouroborus hint in above comment.根据上述评论中的@Ouroborus 提示。 this solved using below coding.这使用下面的编码解决了。 Thanks谢谢

let e = $('[name="amount"]')
updateHandler({target: {name: 'amount', value: parseFloat(e.val() || 0).toFixed(2)}})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM