开发者

Why will an object literal load when in declared in external source file but not when called in a file including an external javascript file file

The code in the external file is

var testing = {
    bugtest: function() {
        alert('No Bugs Here');
    }
}

In the php file I am using

<script type="text/javascript" src="externalScript.js">
    testing.bugtest();
</script>

But this will not work why?

i开发者_StackOverflow中文版f I call the function in the external fil it works

var testing = {
    bugtest: function() {
        alert('No Bugs Here');
    }
}
testing.bugtest()

this will work but this not what I want it to do I want to be able to call the function in the main file? What would the cause of this problem be?


You can not use src attribute and the text node with script elements.

They must be exclusive, e.g. an element each.

So your HTML would look something like...

<script type="text/javascript" src="externalScript.js"></script>
<script type="text/javascript">
    testing.bugtest();
</script>


This

<script type="text/javascript" src="externalScript.js">
testing.bugtest();
</script>

is wrong. You can either specify a src, or run inline code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜