<script id="me" src=".11.3/jquery.min.js"></script
<script>
var oB = document.getElementsById('me');
me.onload = function(){
alert('OK');
}
</script>
Why me.onload
is not triggered after the script is loaded?
<script id="me" src="https://ajax.googleapis./ajax/libs/jquery/1.11.3/jquery.min.js"></script
<script>
var oB = document.getElementsById('me');
me.onload = function(){
alert('OK');
}
</script>
Why me.onload
is not triggered after the script is loaded?
3 Answers
Reset to default 3There are 2 issues:
- a missing
>
at the end of the first line (you have written</script
instead of</script>
) - there is no variable
me
: you have retrieved the script tag into a variableoB
.
Thus, you can fix your code by change me.onload = ...
to ob.onload = ...
.
Moreoever, you should avoid using inlined declaration of event listeners such as <script onload="...">
.
Last but not least, you should use addEventListener
instead of onxxx
: addEventListener vs onclick
document.getElementById
instead of document.getElementsById
oB
instead of me
<script id="me" src="https://ajax.googleapis./ajax/libs/jquery/1.11.3/jquery.min.js"></script
<script>
var oB=document.getElementById('me');
oB.onload=function(){
alert('OK')
}
</script>
But this won't work either because me is already loaded like the other answer states.
before you execute the alert codes, the script tag with id "me" is already downloaded, so despite the syntax error in your code, you can not get the alert.
you can simply use:
<script id="me" onload="alert('OK');"src="https://ajax.googleapis./ajax/libs/jquery/1.11.3/jquery.min.js"></script>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745228552a4617574.html
评论列表(0条)