怎么一打开某个页面就加载某个js的函数?

比如我有个index的页面,在页面里有个function refresh(){ alert("!!!");}的函数,我怎么在一打开index页面的时候就让页面自动调用refresh()函数?

方法一:<body onload="refresh()">
方法二:用window对象直接调用
<script language="javascript">
function refresh(){ alert("!!!");}
window.refresh();
</script>
其他的就相对麻烦
要根据你估具体的需求来找到其他解决方法
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-05-18
<script language="javascript">
refresh();
</script>
直接在脚本里面调用该函数就行了
第2个回答  2012-06-01
<script type=text/javascript>
window.load=refresh();
</script>
第3个回答  2012-05-18
<body onload="refresh()">
相似回答