有没有办法在使用ActiveX旁边的javascript中读取文本文件?

鉴于所有文件(html文件,文本文件等)都在网上, 有没有办法读取文本文件并使用ActiveX旁边的textarea打印它们? 我试过这样,但没达到目标: function getSelectedItem(){    var client = new XMLHttpRequest();    if(document.codeForm.dropList.value ==“foo”)       client.open('GET','foo.txt');    else if(document.codeForm.dropList.value ==“bar”)       client.open('GET','bar.txt');    client.onreadystatechange = function(){       //这实际上显示了文件中的消息       警报(client.responseText);       //但事实并非如此。这只是显示“未定义” // document.codeForm.source.value = client.reponseText;    }    client.send(); } 由于我实际上可以使用文件上下文显示警报消息,我相信会有一些方法可以做到这一点。 (实际上文件的内容似乎进入“client.reponseText”,  但它的数据类型是DOMstring,而不仅仅是String。) 任何建议将非常感激。 谢谢。     
已邀请:
使用jQuery。 http://api.jquery.com/jQuery.get/
$.get("http://www.whatever.com/foo.txt", null, function(response){
    $("#theTextArea").val(response); // where theTextArea is the ID of the textarea you want to put the data into.
});
    
试试这个
document.codeForm.source.innerValue = client.reponseText;
要么
document.getElementById("source").innerHtml = client.responseText;
要么
document.getElementById("source").innerText = client.responseText;
你的textarea需要一个id属性才能使用最后两种方法     

要回复问题请先登录注册