简体   繁体   English

当我尝试使用名为“dinle()”的 output 和 function 时出现错误。 错误代码是:未捕获的类型错误:

[英]I get an error when I try to output the function with the name `dinle()`. The error code is:Uncaught TypeError:

i have to anderstand whats rong with my function我必须了解我的 function 有什么问题

   document.querySelector("#btnClear").addEventListener("click",dinle(event));

        function dinle(event){
            console.log("deneme");
            event.preventDefault();
        }

It seems like event is undefined in your code & or it doesn't have preventDefault Property.似乎事件在您的代码中未定义 & 或者它没有 preventDefault 属性。

If you wan to use inBuild Event in button, you don't need to pass it as args.Try instead..如果您想在按钮中使用 inBuild 事件,则无需将其作为 args 传递。改为尝试..

// event is removed in the dinle fn call
document.querySelector("#btnClear").addEventListener("click",dinle);

        function dinle(event){
            console.log("deneme");
            event.preventDefault();
        }

event.preventDefault() must be at first line of your function definition and event shall not be the attribute in callback, do the following event.preventDefault() 必须在您的 function 定义的第一行,并且 event 不应是回调中的属性,请执行以下操作

 document.querySelector("#btn").addEventListener("click",dinle); function dinle(event){ event.preventDefault(); console.log("deneme"); }
 <button id="btn">CLICK here to run the function </button>

The addEventListener() function takes a type and a listener as parameters. addEventListener() function 将类型侦听器作为参数。 where listener can be a callback function which gets called when the specified type of the event occurs.其中listener可以是一个回调 function 当指定类型的事件发生时被调用。

see documentation文档

It seems like you are passing the result of your dinle(event) which would be undefined since it does not return anything.似乎您正在传递您的dinle(event)的结果,该结果将是未定义的,因为它不返回任何内容。

What is actually causing the Uncaught TypeError is the event parameter, because it cannot be resolved.实际上导致Uncaught TypeError的是事件参数,因为它无法解析。

Try passing the function itself as the parameter: addEventListener("click", dinle)尝试将 function 本身作为参数传递: addEventListener("click", dinle)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我尝试使用tensorflow.js模型进行预测时,出现错误:Uncaught TypeError:无法读取未定义的属性“ length” - When I try to make a prediction using a tensorflow.js model I get the error: Uncaught TypeError: Cannot read property 'length' of undefined 当我尝试添加 API 密钥时,出现错误:TypeError: items.map is not a function - I get the error: TypeError: items.map is not a function, when I try to add my API key 反应为什么我在调用作为参数传递的 function 时收到错误“Uncaught TypeError: createTask is not a function”? - REACT Why do I get the error "Uncaught TypeError: createTask is not a function" when calling a function passed as a parameter? 使用车把我得到这个错误:Uncaught TypeError:$(…).geocomplete不是一个函数 - Using handlebar I get this error :Uncaught TypeError: $(…).geocomplete is not a function 使用 Fetch API 时,我收到此错误: Uncaught (in promise) TypeError: packages.map is not a function - When using Fetch API I get this error: Uncaught (in promise) TypeError: packages.map is not a function 为什么在尝试将作为文本接收的正文分配给 javascript 中的变量时出现未捕获类型错误:response.text 不是函数”错误 - why do I got Uncaught TypeError: response.text is not a function" error when try to assignt body received as text to a variable in javascript 为什么我会收到错误-indexOf未捕获的TypeError - Why i get a error - indexOf Uncaught TypeError 当我尝试在函数中添加 if 时,为什么会出现错误“无法访问的代码”? - Why i get error "unreachable code" when i try to put an if in my function? 我一直收到这个错误“Uncaught TypeError:name.push不是一个函数 <anonymous> :10:7” - i keep getting this error “Uncaught TypeError: name.push is not a function at <anonymous>:10:7” 我正在尝试实现产品的添加和删除,但出现此错误:Uncaught TypeError: props.handleFavouriteClick is not a function - I am trying to implement the addition and removal of the product but I get this error:Uncaught TypeError: props.handleFavouriteClick is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM