22智能在线
新记
怎么一打开某个页面就加载某个js的函数?
比如我有个index的页面,在页面里有个function refresh(){ alert("!!!");}的函数,我怎么在一打开index页面的时候就让页面自动调用refresh()函数?
举报该文章
相关建议 2012-05-18
方法一:<body onload="refresh()">
方法二:用window对象直接调用
<script language="javascript">
function refresh(){ alert("!!!");}
window.refresh();
</script>
其他的就相对麻烦
要根据你估具体的需求来找到其他解决方法
温馨提示:内容为网友见解,仅供参考
当前网址:
https://22.t2y.org/zz/if20hhihx.html
其他看法
第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()">
相似回答
大家正在搜
相关问题
如何让jquery在页面加载的时候自动调用某个函数
怎么一打开某个页面就加载某个js的函数?
js 怎么在一打开页面就加载这个函数。
怎样设置jsp页面开始加载之前执行某个js函数?
怎么能使页面加载时就调用JS函数
js 怎么在一打开页面就加载这个函数。
javascript中如何在脚本中让页面加载时调用一个函数
如何在进入页面的时候调用一个js的函数