判断JS文件是否加载完成再执行操作
记一个JavaScript代码片段。有时需要判断用户是否加载完特定JS文件,然后再相应地触发事件。代码支持现代浏览器运行,不兼容IE7及以下。如果要兼容,可以透过readyState返回状态判断,具体见下文。
function checkJsLoading(url) { var carHead = document.getElementsByTagName('head')[0]; var carJs = document.createElement('script'); carJs.setAttribute('type', 'text/javascript'); carJs.setAttribute('src', url); carHead.appendChild(carJs); carJs.onload = function() { ... } } checkJsLoading('font-awesome.js');
添加IE旧版本兼容支持。
carJs.onreadystatechange = function() { if (carJs.readyState == 'loaded' || carJs.readyState == 'complete') { ... } }
Hi, very nice website, cheers!
——————————————————
Need cheap and reliable hosting? Our shared plans start at $10 for an year and VPS plans for $6/Mo.
——————————————————
Check here: https://www.reliable-webhosting.com/
dapoxetine without a doctor dapoxetine generic https://dapoxetine.confrancisyalgomas.com/
low dose naltrexone autoimmune in pediatric patients https://naltrexoneonline.confrancisyalgomas.com/
what is generic dapoxetine called https://salemeds24.wixsite.com/dapoxetine
using ivermectin to treat heartworms https://ivermectin.mlsmalta.com/
dapoxetine tablets price https://dapoxetine.bee-rich.com/
dapoxetine peptides https://ddapoxetine.com/
where to buy cheap vidalista online https://vidalista40mg.mlsmalta.com/
generic cialis 20 mg price https://wisig.org/
amstyles.com https://amstyles.com/
how does hydroxychloroquine work malaria https://hydroxychloroquinee.com/
difference between viagra and tadalafil https://tadalafil.cleckleyfloors.com/
when do you take viagra https://viaplz.com/
low dose cialis bph https://cleckleyfloors.com/
effectiveness of tamoxifen vs nolvadex https://tamoxifen.mrdgeography.com/
took vidalista didn’t work https://vidalista.mlsmalta.com/
sildenafil dose for bph http://cavalrymenforromney.com/