我在试着学习反应
js和我的html文件(位于路径public/login.html )和js枕文件(按一下按钮)是在src/login.js文件上。
当我运行这段代码时,这个函数没有被调用,控制台显示了在我使用的react之间没有定义的LoginClick()
html文件
<!DOCTYPE html>
<html lang="en">
<head>`your text`
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="stylesheet" href="%PUBLIC_URL%/login.css" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--`your text`
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>React App</title>
</head>
<body>
<div class="login">
<label for="uname">Username</label>
<input type="tex" id="uname"><br>
<label for="pwd">Password</label>
<input type="password" id="pwd"><br>
<button id="login" onclick={LoginClick}>Login</button>
</div>
<script src="../src/login.js"></script>
</body>
</html>我的js
function LoginClick() {
return alert("hey")
}发布于 2022-11-27 19:58:58
只需将{LoginClick}更改为LoginClick()即可。
https://stackoverflow.com/questions/74593116
复制相似问题