警报('你好');在pageLoad()函数中工作? [英] Does alert('hello'); work in pageLoad() function?

查看:45
本文介绍了警报('你好');在pageLoad()函数中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

警报在pageLoad中不起作用,为什么?谢谢

Alert does not work in pageLoad, why? thanks

<html>
<head>  
    <script type="text/javascript">
        function pageLoad()
        {
            alert('hello');
        }
    </script>
</head>
<body />
</html>

发现问题: Dave Ward建议由于我的网页没有脚本管理器(为我调用PageLoad)。这就是我感到困惑的原因。当没有脚本管理器时,我从未意识到必须自己调用它。

Problem found: Dave Ward suggests that since my page does not have a script manager (which calls PageLoad for me). that is the reason I was puzzled. I never realised I had to call it for myself when there was no script manager.

推荐答案

是的,但你需要调用它某处:

Yes, but you need to invoke it somewhere:

<script type="text/javascript">

    function pageLoad()
    {
        alert('hello');
    }

    pageLoad();  // invoke pageLoad immediately

</script>

或者你可以延迟它直到加载所有内容:

Or you can delay it until all content is loaded:

<script type="text/javascript">

    function pageLoad()
    {
        alert('hello');
    }

    window.onload = pageLoad;  // invoke pageLoad after all content is loaded

</script>

这篇关于警报('你好');在pageLoad()函数中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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