[英]How to display content of javascript source file?
How to display content of javascript source file? 如何显示javascript源文件的内容? I have the url of the source file.
我有源文件的URL。 I just want to display it in a text area and alert box.
我只想在文本区域和警报框中显示它。 No matter the size of the file.
无论文件大小。
<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>
You can do it like this: 您可以这样做:
$.get("file.js", function(file) {
$("textarea").val(file);
});
http://api.jquery.com/jQuery.get/ http://api.jquery.com/jQuery.get/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.