项目中有个JS,需要动态引入。

写法如下:

<script>
document.write('<script src="http://www.z4.com/js/xxxx.js?r=' + Math.random() + '"></script>');
</script>

发现一直有错误。

原因是字符串中的</script><script>竟然匹配了,导致后面的 ');</script> 成为了HTML文本。

解决方法很简单,将</script>分割开就好了。

<script>
document.write('<script src="http://www.z4.com/js/xxxx.js?r=' + Math.random() + '"></scri' + 'pt>');
</script>

注意以后在<script></script>中的字符串中使用到</script>,都需要分割处理。否则还会出现此BUG!

 

相关文章:

  • 2022-01-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-11
  • 2022-12-23
  • 2022-02-02
猜你喜欢
  • 2022-12-23
  • 2021-07-02
  • 2021-08-31
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案