如何将onload事件添加到div元素? [英] How to add onload event to a div element?

查看:648
本文介绍了如何将onload事件添加到div元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何将一个onload事件添加到一个元素?我可以使用:

How do you add an onload event to an element? Can I use:

<div onload="oQuickReply.swap();" ></div>

for this?

for this?

推荐答案

不,你不能。最简单的方法是将函数调用直接放在元素之后

No, you can't. The easiest way to make it work would be to put the function call directly after the element

示例:

...
<div id="somid">Some content</div>
<script type="text/javascript">
   oQuickReply.swap('somid');
</script>
...

或者 - 甚至更好 - 就在< / body>

or - even better - just in front of </body>:

...
<script type="text/javascript">
   oQuickReply.swap('somid');
</script>
</body>

...所以它不会阻止下面的内容加载。

...so it doesn't block the following content from loading.

这篇关于如何将onload事件添加到div元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆