我想知道是否有其他方法可以使用事件将元素传递给函数, 例如,如果我有一个输入:
<input name="myname" onChange={onChange}/>
然后在我的 onChange 函数中我会看到这个:
onChange=e=>{
console.log(e.target.name)
}
它会打印“myname”, 我想给出另一个值有没有办法做到这一点?例如
<input name="myname" othervalue="hi" onChange={onChange}/>
当然:
onChange=e=>{
console.log(e.target.name)
console.log(e.target.othervalue)
}
提前致谢! 编辑:除了值,因为我需要它用于 onChange 表单。
最佳答案
更改:
console.log(e.target.othervalue)
致:
console.log(e.target.getAttribute('othervalue'));
可以使用该方法获取自定义属性值,
关于javascript - 从输入传递事件元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60474756/