简体   繁体   English

OnClick Javascript似乎无法正常运行

[英]OnClick Javascript doesn't seem to be working properly

I'm doing a project that involves a console-like panel. 我正在做一个涉及类似控制台的面板的项目。 I've looked around on Google, but I can't solve this problem! 我在Google上四处查看,但无法解决此问题! I got the load() working, but the click() isn't. 我让load()工作,但click()没有。

<html>

<head>
<script type="text/JavaScript">
function load()
{
  document.getElementById("display").innerHTML="Hello!";
}

function click()
{
  alert("Clicked");
}
</script>
</head>

<body style="background-color:red;" onload="load()">
<div id="display" style="position:absolute; right:0px; left:0px; bottom:0px; width:100%; height:87%; background-color:white;"></div>
<div style="position:absolute; left:0px; width:10%;">
<b>Input:</b>
<input id="text" maxlength=50 />
<input type="button" onclick="click()" value="OK" />
</div>

</body>
</html>

Help if you can, please! 可以的话请帮助! Thanks. 谢谢。 :) :)

Just rename your click function to something else, eg myclick and it will work :) 只需将您的click函数重命名为其他名称,例如myclick ,它将起作用:)

It happens because calling click() you trigger the click event again but not your function. 发生这种情况是因为调用click()会再次触发click事件,但不会触发函数。

Check it here : http://jsfiddle.net/rHyZ7/ 在这里检查http : //jsfiddle.net/rHyZ7/

I experienced the same issue when naming my function clear() 命名函数clear()时遇到了相同的问题

changing the function name fixed the issue 更改功能名称解决了该问题

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM