简单的Javascript无效:< div onload =" alert(" Hi");" > [英] Simple Javascript not working: <div onload="alert("Hi");" >
本文介绍了简单的Javascript无效:< div onload =" alert(" Hi");" >的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正试图让一个非常简单的 alert()
在div加载时弹出。不幸的是它不起作用,我无法弄清楚原因。
I'm trying to get a really simple to alert()
to pop up as soon as a div loads. Unfortunately it is not working, and I can't figure out why.
以下是代码:
<html>
<head>
<title>My Site</title>
<link rel="stylesheet" type="text/css" href="style2.css">
<script type="text/javascript" src="js/jquery_1.4.2.js"></script>
<script type="text/javascript" src="js/alertjs.js"></script>
</head>
<body>
<div id="background_logo" onload="pop_alert();">
<img src="mysiteLogo.png">
</div>
<div id="signup">
<p id="instruction"> Get on board! </br> Enter your email to receive updates:</p>
<script type="text/javascript" src="js/form-validation.js"></script>
</div>
</body>
</html>
JavaScript就是这样:
And the JavaScript is just this:
function pop_alert(){
alert("This is an alert");
}
推荐答案
您无法附加 onload
到 div
。尝试将其放入< body>
:
You can't attach onload
to a div
. Try putting it in the <body>
:
<body onload="pop_alert();">
这篇关于简单的Javascript无效:< div onload =" alert(" Hi");" >的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文