首页 > 其他 > 详细

动态脚本(兼容所有浏览器)

时间:2018-07-08 15:02:22      阅读:166      评论:0      收藏:0      [点我收藏+]

function loadScriptString(code){

  var script = document.createElement("script");

  script.type = "text/javascript";

  try{

    script.appendChild(document.createTextNode(code));

  } catch(ex){

    script.text = code;

  }

  document.body.appendChild(script);

}

调用示例

loadScriptString("function sayhi(){alert(‘hi‘);}")

动态脚本(兼容所有浏览器)

原文:https://www.cnblogs.com/msg001/p/9280040.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!