开发者

How to test if a script load succeeded/failed?

I've got a sample script as below. I wanna see if local.js or online/latest.js failed to load. Is it possible?

<html>
<title>My JQuery Test</title>
<head>
    <!--<script type="text/javascript" src="jquery/jquery.local.js"></script>-->
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
    <script type="text/javascript" language="javascript">
        $(document).ready(function () {
            $("#Buttons-theTestAlert").click(function () {
                alert("`Test Alert` clicked");
            });
        });
    </script&开发者_运维技巧gt;
</head>
<body>
    <button id="Buttons-theTestAlert">Test Alert</button>
</body>
</html>


You can test

if (myFunction) myFunction()
else alert('not loaded (yet)')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜