簡體   English   中英

如何顯示javascript源文件的內容?

[英]How to display content of javascript source file?

如何顯示javascript源文件的內容? 我有源文件的URL。 我只想在文本區域和警報框中顯示它。 無論文件大小。

<pre>function getFile() {  
  var url = "http://example.com/s/js/file.js";
if(window.XMLHttpRequest)
{
    //code for IE7+, FF, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
}
else
{
    //code for IE5,IE6
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function redraw()
{
    if(xmlhttp.readyState==4 && xmlhttp.status==200)
    {
        alert(xmlhttp.responseText);
    }
}
xmlhttp.open("GET",url,false);
xmlhttp.send();
}
</pre>

您可以這樣做:

$.get("file.js", function(file) {
    $("textarea").val(file);
});

http://api.jquery.com/jQuery.get/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM