![](/img/trans.png)
[英]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.