【问题标题】:Handler assigned via onclick attribute is not getting invoked通过 onclick 属性分配的处理程序没有被调用
【发布时间】:2013-10-24 04:22:57
【问题描述】:

我不知道问题出在哪里,但是 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>

【问题讨论】:

  • myfmyF 不同。
  • 你的问题标题看起来更像是一个广告,改变它。添加更多细节,比如你想做什么,你得到了什么等。
  • 跑题了,你为什么要使用字体和中心标签,它们应该是死的

标签: javascript html css


【解决方案1】:
   <button type="button" id="register" onClick="myF()">Register Info</button>

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

它会起作用的。

【讨论】:

  • 我做到了。谢谢!但 document.getElementById("link").display="inline";不工作!
  • @user2885253:您需要.style.display = "inline",可能还需要一些基本课程,以及您在研究和故障排除方面的更多努力。
  • document.getElementById("link").style.display="inline";像这样使用它。
【解决方案2】:

由于您以错误的格式编写函数,请以骆驼案例的形式编写它 你把函数写成 myf() 写成 myF()...

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

它会起作用的

【讨论】:

    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 2012-10-17
      • 1970-01-01
      • 2011-01-31
      • 2017-01-09
      • 1970-01-01
      • 1970-01-01
      • 2014-05-01
      • 2016-08-03
      • 1970-01-01
      相关资源
      最近更新 更多