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

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

问题描述

如何将onload事件添加到元素?

How do you add an onload event to an element?

我可以使用:

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

为此吗?

推荐答案

不,您不能.最简单的方法是将函数调用直接放在元素

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天全站免登陆