...
<head>
<script type="text/javascript" src="a.js"></script>
</head>
<body>
<button id="test">click me</button>
<script type="text/javascript">
show();
document.getElementById( test ).onclick=function(){
show();
}
</script>
</body>
</html>
the code above:
我将<代码>a.js载于<head>
tag,载于a.js
。 这里有<条码>b.js,由下列单位创建:
document.getElementsByTagName( head )[0].appendChild(document.createElement( script )); function show(){...}
b.js;
now I want to invoke show()
which in the b.js,but it goes error,because b.js hasn t loaded;
我想增加一些编码,以阻挡页数。
实际上, b. 在援引功能显示时,应装满;
but what about click event?in addition,I must put the show() in the page.
现在,我把另一支 j(基地.js)放在主角上,上述法典就是这样:
...
<head>
<script type="text/javascript" src="base.js"></script>
<script type="text/javascript" src="a.js"></script>
</head>
<body>
<button id="test"></button>
<script type="text/javascript">
//invoke button click event from base.js and b.js
</script>
</body>
...
for example,there are two click events bind to base.js and b.js(loaded ansync by a.js),when users click the button in the page,the event binded in base.js will be invoked immediately,but then...error...
我必须把援引人置于主角。