[英]For "onevent change" in javascript I am trying to access the parameter of the function, but getting an error as "undefined"
I have a code as below:我有一个代码如下:
<input type="text" id="GAMES" name="OwnGames" width="100%" onChange="ValidateText(document.getElementById('GAMES'))";
Javascript: Javascript:
function ValidateText(e,Games) {
console.log(Games.id);
var text_value=e.target.value;
console.log(text_value);
}
Console logs is correctly giving event e, but giving an error as Games is undefined.控制台日志正确给出事件 e,但由于游戏未定义而给出错误。
After removing argument Games, I am getting an error as e is undefined.删除参数游戏后,我收到一个错误,因为e 未定义。
We have an easy way to access all the element property and values.我们有一种简单的方法来访问所有元素属性和值。 Please refer the snippet.请参考片段。
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.