问题
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:
- Use
""
not“
in your code - Try to write your js code before html "button" code.
- And try also to add a comma in the end of onclick script.
来源:https://stackoverflow.com/questions/45852344/alert-pop-up-not-showing