[英]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 上市
src src
//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.