admin管理员组文章数量:1287524
I have been looking at the following code for a few minutes and the problem is escaping me. How can I make each of these events that produce alerts work?
<html>
<head></head>
<body>
[ <span id="trad_alert">traditional alert</span> ]
[ <span onclick="inlineAlert ();">inline alert</span> ]
<script type="txt/javascript">
document.getElementById("trad_alert").onclick = function () {
alert ("traditional alert");
}
function inlineAlert () {
alert ("inline alert");
}
</script>
</body></html>
Searching Stack Overflow or the web produce numerous examples that appear identical to what I'm trying, but yet mine continues to fail.
I have been looking at the following code for a few minutes and the problem is escaping me. How can I make each of these events that produce alerts work?
<html>
<head></head>
<body>
[ <span id="trad_alert">traditional alert</span> ]
[ <span onclick="inlineAlert ();">inline alert</span> ]
<script type="txt/javascript">
document.getElementById("trad_alert").onclick = function () {
alert ("traditional alert");
}
function inlineAlert () {
alert ("inline alert");
}
</script>
</body></html>
Searching Stack Overflow or the web produce numerous examples that appear identical to what I'm trying, but yet mine continues to fail.
Share Improve this question edited Jan 10, 2023 at 9:29 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Apr 30, 2011 at 4:40 soscsosc 1541 silver badge6 bronze badges 1- It looked ok to me too so I pushed it to jsbin (jsbin./afajo5/edit) and it ran just fine. At least in Chrome. – LeRoy Commented Apr 30, 2011 at 4:55
3 Answers
Reset to default 4Your script type is wrong.
Either change it to <script type="text/javascript">
or remove the type
altogether.
If I change the mime type on the script block to text/javascript
(you have txt
) it works fine for me in Fx4.
You're missing an e in text/javascript
. It works with one:
http://jsfiddle/kFUMX/
Have a look at Firebug for javascript debugging too.
本文标签: Simple JavaScript events alert using inline and traditional methodsStack Overflow
版权声明:本文标题:Simple JavaScript events: alert using inline and traditional methods - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741292434a2370626.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论