简体   繁体   English

如何在没有onclick事件的情况下调用javascript方法

[英]how to call javascript method without onclick event

I have a JavaScript function like this: 我有这样的JavaScript函数:

<script type="text/javascript" src="http://tem.parstools.com/zeos/js/animatedcollapse.js"></script>

<script type="text/javascript">
animatedcollapse.addDiv('bannertop', 'fade=0,speed=200,persist=1')

animatedcollapse.ontoggle=function($, divobj, state){
if (divobj.id=="bannertop") //only react to these two collapsible DIVs
document.getElementById(divobj.id+"-toggle").src=(state=="block")? "image1.png" : "image2.png"
}

animatedcollapse.init()
</script>

This function is called when user click on the specific image like: 当用户单击特定图像时,将调用此函数:

<a href="javascript:animatedcollapse.toggle('bannertop')"><img id="bannertop-toggle" src="image_source" /></a>

But, I want first time my site loading this function calling automatically. 但是,我想我的站点第一次加载此函数自动调用。

sorry for my weak English typing. 对不起,我英文输入能力很差。
Can any body can help me? 任何人都可以帮助我吗?
thanks 谢谢

You can simply call the method in the script 您可以简单地在脚本中调用方法

animatedcollapse.toggle('bannertop')

inside the <script> tag. <script>标记内。 You might want to put this code at the bottom of the html file, right before the </body> tag. 您可能想将此代码放在html文件的底部,就在</body>标记之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM