加载后:
$('#buy-div').load('../buyBar/buyBar.html',function() {
//do some things here
});
我想包括这个:
<script src="../buyBar/BuyBar.js"></script> //access some html that does not exist
因为在这个js
我正在寻找一些html
仅在 .load
之后才存在功能完成。 (例如 getElementById
或 $('input').keyup(function() {
发生在 .load
完成之前。
最佳答案
只需将 html 加载后要运行的代码放入函数中即可。然后在.load('../buyBar/buyBar.html')
的回调函数中调用该函数
假设“../buyBar/BuyBar.js”最初包含
document.getElementByID("#someElement").innerHTML = "...";
您可以将其更改为
function someFunction(){document.getElementByID("#someElement").innerHTML = "...";}
现在只需输入 <script src="../buyBar/BuyBar.js"></script>
在 <head>
照常。然后执行以下操作:
$('#buy-div').load('../buyBar/buyBar.html',function() {
someFunction();
//do other stuff
});
关于javascript - 加载html后如何加载js文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56785729/