Reference: http://www.tianshan277.com/563.html
effect:
html:
<! DOCTYPE HTML> <HTML lang = "EN"> <head> <Meta charset = "UTF-. 8"> <title> JS loading </ title> <Script> function errorload (elem) { // CDN error IF ( elem.getAttribute ( 'Data-errorTimes') ==. 1 ) { elem.onerror = null ; // perform after onerror event, is set to clear onerror onerror = null event. return ; } elem.setAttribute ( 'Data-errorTimes',. 1 ); var _src = elem.getAttribute ( 'Data-localSrc' ); } The loadScript (_src, Prevel) { // bring local JS var _el = document.createElement ( 'Script' ); _el.src = _src; IF (Prevel) { prevEl.parentNode.insertBefore (_el, prevEl.nextSibling); } the else { document.body.appendChild (_el); } } </ Script> </ head> <body> <P> products </ p> <P> product 2 </ p> <P> product three </ p> <p> product four </ p> <p> product five </ p> <Data-Script localSrc = "JS / jquery.js" type = "text / JavaScript" the src = "https://cdn.bootcss.com/jquery/1.8.2/jquery.min.js" the onerror = "errorload ( the this); "> </ Script> // this cdn version is correct, the error can be modified version of the test is then test the </ body> </ HTML>