未调用通过 onclick 属性分配的处理程序

Handler assigned via onclick attribute is not getting invoked

本文关键字:分配 处理 程序 属性 onclick 调用      更新时间:2023-09-26

我不知道问题是什么,但是JavaScript没有被执行!我尝试了很多次,但我没有看到任何错误。

<html>
<head>
<title>Log In Page</title>
<script>
function myf()
{
document.getElementById("name").disabled=true;
document.getElementById("reason").disabled=true;
document.getElementById("register").disabled=true;
document.getElementById("link").display="inline";
alert("You have successfully registered.");
}
</script>
</head>
<body bgcolor="black">
<center><h1 style="font-family:Agency FB;font-size:100px;color:#3333FF;letter-spacing:50px;text-shadow: 10px 10px 10px #FF9933;">My Profile</h1></center>
<center><p style="font-family:Ubuntu Mono Bold;color:#3333FF;">You are requested to FILL IN these particulars.</p></center>
<font color="#07C6F6" face="Arial">
<center>Enter Your Name:<input type="text" id="name"><br><br>
Why Do You Want to See This Profile:<input type="text" id="reason"><br></center>
</font>
<br>
<br>
<center><button type="button" id="register" onClick="myF()">Register Info</button><br>
<p id="link" style="font-family:Arial;display:none;"><a href="Profile.html">View Profile</a></p></center>
</body>
</html>
   <button type="button" id="register" onClick="myF()">Register Info</button>

将调用函数 myF() 更改为 myf()

它会起作用。

由于您以错误的格式编写函数,因此将其写成骆驼案例的形式你已经把函数写成myf()写成myF()...

在按钮的位置,您已经写了正确的写法,就像通常在创建函数时一样。

它将起作用

您只需要更正按钮的onClick中的方法调用即可。 它的 myF()