[英]I am facing an error 'data' is undefined when trying to access the function parameter as mentioned in the comment in below code
[英]For "onevent change" in javascript I am trying to access the parameter of the function, but getting an error as "undefined"
我有一个代码如下:
<input type="text" id="GAMES" name="OwnGames" width="100%" onChange="ValidateText(document.getElementById('GAMES'))";
Javascript:
function ValidateText(e,Games) {
console.log(Games.id);
var text_value=e.target.value;
console.log(text_value);
}
控制台日志正确给出事件 e,但由于游戏未定义而给出错误。
删除参数游戏后,我收到一个错误,因为e 未定义。
我们有一种简单的方法来访问所有元素属性和值。 请参考片段。
function ValidateText(event) { var text_value= event.target.value; var id = event.target.id; console.log(`value : ${text_value}, id : ${id}`) }
<input type="text" id="GAMES" name="OwnGames" width="100%" onChange="ValidateText(event)" >
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.