Try this
<body onload="alert('Hello World')">
<h1>Hello World!</h1>
</body>
The issue is with nested quotes
Here is a working demo
質問
<body onload="alert("Hello World")">
<h1>Hello World!</h1>
</body>
why doesn't this work?
EDIT Additionally, why does chrome dev tools report "Uncaught SyntaxError: Unexpected token } " that as the error message?
Thanks, funbeans
解決 2
Try this
<body onload="alert('Hello World')">
<h1>Hello World!</h1>
</body>
The issue is with nested quotes
Here is a working demo
他のヒント
The issue is with double quotes, you need to escape them:
<body onload="alert(\"Hello World\")">
Or use single quotes:
<body onload="alert('Hello World')">
This happens because when you use double quote HTML think that your attribute is ended and contains of only alert(
and the rest "Hello World")"
is another attribute.