繁体   English   中英

对于javascript中的“oneevent change”,我试图访问函数的参数,但收到“未定义”的错误

[英]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.

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