起因:

我们在用js动态写入script时,会导致</script>后面的所有语句都变为普通文本,导致html展示无效, 所以我们需要规避</script>问题.

 

解决方案一(亲测好用)

添加 \/ 用来转议/

var script=$('<script>alert("I am a script element")<\/script>');
$('body').append(script);

 


解决方案二 避免在使用中出现/script (未试验)

 

var script = document.createElement('script');
script.type = 'text/jacascript';
script.src = 'url'; //填自己的js路径
$('body').append(script);

 

 参考链接:https://segmentfault.com/q/1010000007998877?_ea=1517884

相关文章:

  • 2022-12-23
  • 2021-08-08
  • 2021-11-19
  • 2021-07-16
  • 2022-02-02
  • 2022-12-23
猜你喜欢
  • 2021-06-07
  • 2021-10-20
  • 2021-08-29
  • 2021-09-29
  • 2022-12-23
  • 2022-12-23
  • 2022-01-16
相关资源
相似解决方案