![](/img/trans.png)
[英]Wait On Lib (IronRouter) causing HTML to not load after loading JS file
[英]How to load a js file after loading html?
我加載后:
$('#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
我正在尋找僅在.load
函數完成后才存在的一些html
。 (例如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
});
我發現我可以通過在.load
完成后加載它來做到這一點:
let script = document.createElement('script');
script.src = "../buyBar/Pay.js";
document.body.append(script);
這有效,但我不確定是最好的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.