I am trying to refer a external javascript file by calling a function in that file as
<script type="text/javascript" src="external.js">
display('hell0');
</script>
But this code is not working. If i refer the file in separdate script tag it works fine.
<script type="text/javascript" src="external.js"></script>
<script type="text/javascript">
display('hell0');
</script>
Why the first case is not working?
If you use the src
attribute to specify an external javascript file to be included you cannot have contents to this script
tag. The second case is the correct way.
Quote from the specification :
The script may be defined within the contents of the SCRIPT element or in an external file. If the src attribute is not set, user agents must interpret the contents of the element as the script. If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.