Alert pop-up not showing

巧了我就是萌 提交于 2020-01-03 02:56:12

问题


I can’t find the problem with my simple code. The button shows, but the alert pop-up doesn’t show when I click on it.

What am I doing wrong?

<DOCTYPE! html>
<html>


<body>
<h1>This will be a test for Javascript</h1>
<button> onclick=“myFunction()”>I like it</button>

<script>
 function myFunction() {
     alert(“are you sure?”);
}
</script>
</body>
</html>


回答1:


Problem in smart quotes. Use

"

quotes.




回答2:


<button onclick="ok()">Ok</button>

<script>
function ok() {
    alert("ok");
}
</script>



回答3:


  1. Use "" not in your code
  2. Try to write your js code before html "button" code.
  3. And try also to add a comma in the end of onclick script.


来源:https://stackoverflow.com/questions/45852344/alert-pop-up-not-showing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!