我怎样才能得到JavaScript代码作为文本从.js插入到HTML页面? [英] How can I get javascript code as text from .js to be inserted into an html page?

查看:69
本文介绍了我怎样才能得到JavaScript代码作为文本从.js插入到HTML页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由ajax发表评论

由ajax发表评论

  let xhr = new XMLHttpRequest(); 
xhr.open('GET','test.js');
xhr.send();
xhr.onreadystatechange = function(){
if(xhr.readyState === 4&& xhr.status == 200){
console.log(xhr.responseText);
}
};


I'm new on stackoverflow and I apologize in advance for any wrong way to ask a question.

解决方案

by ajax:

    let xhr = new XMLHttpRequest();
    xhr.open('GET', 'test.js');
    xhr.send();
    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4 && xhr.status == 200) {
            console.log(xhr.responseText);
        }
    };

这篇关于我怎样才能得到JavaScript代码作为文本从.js插入到HTML页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆