dynamically change script src client-side

后端 未结 3 631
忘了有多久
忘了有多久 2020-12-10 17:23

I have an HTML page which contains:

  • a
提交评论

  • 2020-12-10 17:43
    function getData(title){
        document.getElementById("widget").src= (title == "ro" || title == "-") ? "js1.js" : "js2.js";
    }
    
    0 讨论(0)
  • 2020-12-10 17:46

    do simply:

    function getData(title) {
        switch(title) {
            case "ro":
                document.getElementById("output").innerHTML = '<script id="widget" type="text/javascript" src="js1.js" />';
                break;
            case "en":
                document.getElementById("output").innerHTML = '<script id="widget" type="text/javascript" src="js2.js" />';
                break;
            default:
                void(0);
        }
    }
    
    0 讨论(0)
  • 提交回复
    热议问题