how to add a js condition

前端 未结 2 1414
遇见更好的自我
遇见更好的自我 2021-01-25 07:26

Hi
I want to write a condition in JS that will result in adding an external js.
For example if the condition is x > 2 and it is true then i want it to load a different e

相关标签:
2条回答
  • 2021-01-25 08:10
      var fileref=document.createElement('script')
      fileref.setAttribute("type","text/javascript")
      if (x > 2){
         fileref.setAttribute("src", "/js/file1.js")
     }else{
         fileref.setAttribute("src", "/js/file2.js")
     }
     document.body.appendChild(fileref);
    
    0 讨论(0)
  • 2021-01-25 08:23

    you can write:

    if(conditon)
       $('body').append("<script src='whatever'><" + "/script>");
    
    0 讨论(0)
提交回复
热议问题