js 動態創建標簽 並執行其標簽中的內容


//獲取head的標簽
var head= document.getElementsByTagName('head')[0];
//創建script標簽
var script= document.createElement('script');
//屬性賦值
script.type= 'text/javascript';
//下面為必要操作 否則將不能使用script標簽中的內容
script.onload = script.onreadystatechange = function() {
if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete" ) {
script.onload = script.onreadystatechange = null;
} };
//添加src屬性值
script.src= url;(url為你自己的添加js 文件的路徑)
head.appendChild(script);


------------此處討論跳入后台加載js文件的一種方式 (后台使用重定向)---------------
<script type="text/javascript" src="http://localhost:8080/aaa/cc/yyxx/hj/getJsInformation.action"></script>

@RequestMapping(value = "/getJsInformation.action")
public String getJsInformation(HttpServletResponse response, HttpServletRequest request,@RequestParam HashMap<String, Object> map) {
List<HashMap<String, Object>> list = service.getJS(map);
return "redirect:"+"http://localhost:8080/upload/abc.js";//沖定向到你js文件全路徑地址即可
}
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM