简体   繁体   English

未捕获的ReferenceError:未在HTMLButtonElement.onclick上定义测试

[英]Uncaught ReferenceError: testing is not defined at HTMLButtonElement.onclick

I know this kind of question has been asked tons of time before. 我知道这种问题已经被问了很多次了。

So sorry for that i am new to react js, JavaScript etc. And i am using react app tool for this project. 非常抱歉,我是React JS,JavaScript等的新手。我正在为该项目使用react app工具。

I am preparing login form. 我正在准备登录表格。 So feature is simple when user click on login button. 因此,当用户单击登录按钮时,功能很简单。 function should be called. 函数应该被调用。

my function is in src/xyz and i want it to invoke from my index.html. 我的函数在src / xyz中,我希望它从index.html调用。 but it fails. 但是失败了。 and give exception 并给予例外

  • public 上市

    • index.html index.html
    • see.js see.js
  • src src

    • xyz.js xyz.js

 //my code in src/xyz.js function testing(){ console.log("welcome user") } //this code works which is in same directory // public/see.js function hello(){ console.log("hi") } 
 <!DOCTYPE html> <html lang="en"> <head> <script type = "text/javascript" src="/src/index.js"></script> <script type = "text/javascript" src="./see.js"></script> <script type = "text/javascript" src="/src/xyz.js"></script> </head> <body> <div class="root"> <h1>Login form</h1> <table id=login> <tr> <td>UserName</td> <td><input type="email" /> </td> </tr> <tr> <td>password</td> <td><input type="password" /></td> </tr> <tr> <td></td> <td> <button type="submit" id="login" onclick="testing()">Log In</button> </td> </tr> </table> </div> </body> </html> 

it's from your src attribute, notice that you have "./" for see.js and just "/src/xyz" you should probably change it to "./src/xyz.js" 它来自您的src属性,请注意,对于see.js,您使用“ ./”,而对于“ / src / xyz”,您应该将其更改为“ ./src/xyz.js”

  <script type = "text/javascript" src="./see.js"></script> <script type = "text/javascript" src="/src/xyz.js"></script> 

first you know react structure in react you don't invoke js file into public/index.html but using src/index.js file you access all the content. 首先,您知道React中的react结构,您不会将js文件调用到public / index.html中,但是使用src / index.js文件可以访问所有内容。 all file import in src/index.js 所有文件导入src / index.js

暂无
暂无

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

相关问题 未捕获的ReferenceError :(函数)未在HTMLButtonElement.onclick中定义 - Uncaught ReferenceError: (function) not defined at HTMLButtonElement.onclick 未捕获的ReferenceError:未在HTMLButtonElement.onclick中定义查找 - Uncaught ReferenceError: lookup is not defined at HTMLButtonElement.onclick 未捕获的 ReferenceError:showCurrentPage 未在 HTMLButtonElement.onclick 中定义 - Uncaught ReferenceError: showCurrentPage is not defined at HTMLButtonElement.onclick 未捕获的 ReferenceError:在 HTMLButtonElement.onclick 中未定义 postAcmgForm - Uncaught ReferenceError: postAcmgForm is not defined at HTMLButtonElement.onclick 未捕获的ReferenceError:HTMLButtonElement.onclick中未定义submitToAPI - Uncaught ReferenceError: submitToAPI is not defined at HTMLButtonElement.onclick 未捕获的 ReferenceError:id 未在 HTMLButtonElement.onclick 中定义 - Uncaught ReferenceError: id is not defined at HTMLButtonElement.onclick Uncaught ReferenceError: (function) is not defined at HTMLButtonElement.onclick - Uncaught ReferenceError: (function) is not defined at HTMLButtonElement.onclick 未捕获的ReferenceError:在HTMLButtonElement.onclick中未定义函数 - Uncaught ReferenceError: function is not defined at HTMLButtonElement.onclick 未捕获的ReferenceError:未在HTMLButtonElement.onclick上定义toggleFunction - Uncaught ReferenceError: toggleFunction is not defined at HTMLButtonElement.onclick 未捕获的 ReferenceError:异步未在 HTMLButtonElement.onclick 中定义 - Uncaught ReferenceError: async is not defined at HTMLButtonElement.onclick
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM