<script language = javascript></script>JS文件是不需要上面标记的!
TO : TSD(因为有你而精彩) 你说的没错.但是那个文件已经定了.是有 <script language = javascript> </script>的.
TO:xishanlang2001(西山狼2000) 我看过你说的XMLHTTP了. 但是他好像是个组件(Active X)吧. 组件不可以用的. 你按照你说的写了如下代码. 它确实是好用的.我可以把JS文件都读出来. 然后再去掉头和尾. 但是然后呢. 真接document.write好像不行. 不去掉头和尾真接document.write也是不行. 去动态的设script的SRC好像也不行.还有没有什么别的好办法.<script type="text/javascript"> var xmlhttp function Pause(obj,iMinSecond){ if (window.eventList==null) window.eventList=new Array(); var ind=-1; for (var i=0;i<window.eventList.length;i++){ if (window.eventList[i]==null) { window.eventList[i]=obj; ind=i; break; } }
if (ind==-1){ ind=window.eventList.length; window.eventList[ind]=obj; } setTimeout("GoOn(" + ind + ")",iMinSecond); } function GoOn(ind){ var obj=window.eventList[ind]; window.eventList[ind]=null; if (obj.NextStep) obj.NextStep(); else obj(); } function loadXMLDoc(url) { // code for Mozilla, etc. if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest() xmlhttp.onreadystatechange=xmlhttpChange xmlhttp.open("GET",url,true) xmlhttp.send(null) } // code for IE else if (window.ActiveXObject) { alert('right'); xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") if (xmlhttp) { xmlhttp.onreadystatechange=xmlhttpChange xmlhttp.open("GET",url,true) xmlhttp.send() alert('right'); // when code run to here, you should be wait until the source loaded into client side. I don't know how to sleep here in javascripts. alert (xmlhttp.responseText); document.write(xmlhttp.responseText); } } }function xmlhttpChange() { if (xmlhttp.readyState==4) { if (xmlhttp.status==200) { } else { } } }</script> <HTML> <HEAD> <TITLE> New Document </TITLE> </HEAD> <BODY onload = ''> <input type = button name = button value = button onclick = 'loadXMLDoc("http://xxxx.xxxx.xxxx.xxx.js");'> </BODY> </HTML>
但是那个文件已经定了.是有 <script language = javascript> </script>的.那么这个js文件就是错误的!无论谁用都是错误的,也不可能是什么“网络资源”
你可以试着访问:http://xxxx.xxxx.xxx/test.js看能不能下载,
如果可以,建议可以下载自己再另做处理
我写了两段代码.
test.html
---------------------------
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<script type="text/javascript" src="D:/effect.js"></script>
<BODY onload = ''>
<input type = button name = button value = button onclick = 'test();'>
</BODY>
</HTML>
--------------------------------------------------------------------
effect.js(情况1)
--------------------------------------------------------------------function test(){
alert('right');
}这个做一点问题也没有.
--------------------------------------------------------------------
但实际上这个js文件是这样写的
effect.js(情况2)
并且它是网络的资源. 我们不能也不能想办法改掉他.
---------------------------------------------------------------------
<script language = javascript>
function test(){
alert('right');
}
</script>
这样的话就会出错.
----------------------------------------------------------------------所以. 从上面来看的话. 我在JS文件不能写JS的头和尾. 写上的话一定出错. 那么怎么然决呢.
这样不行. 我试过了.
TO:lantersen(蓝水仁).
我不用网络. 用本地的也不行.当然这个问题的关键是在JS文件里有头和尾.
>>如果可以,建议可以下载自己再另做处理
这样做是不可以的.因为它是网络资源.并且有可能动态更新.再做一个copy文件是不允许的.
不过...楼主打算用来作什么呢?这个js文件似乎不是你的.
是的.这个文件是公司的通用文件.我只是要调里面的某人函数我实现我的业务逻辑.>>用xmlhttp把抓取过来,然后进行字符串分析处理,去掉标签,写入一个script块里.
你说的这个办法看起来是可行的.但是我不知道什么是xmlhttp.你有示例性的代码吗.
你说的没错.但是那个文件已经定了.是有
<script language = javascript>
</script>的.
我看过你说的XMLHTTP了. 但是他好像是个组件(Active X)吧. 组件不可以用的.
你按照你说的写了如下代码. 它确实是好用的.我可以把JS文件都读出来. 然后再去掉头和尾. 但是然后呢. 真接document.write好像不行. 不去掉头和尾真接document.write也是不行. 去动态的设script的SRC好像也不行.还有没有什么别的好办法.<script type="text/javascript">
var xmlhttp
function Pause(obj,iMinSecond){
if (window.eventList==null) window.eventList=new Array();
var ind=-1;
for (var i=0;i<window.eventList.length;i++){
if (window.eventList[i]==null) {
window.eventList[i]=obj;
ind=i;
break;
}
}
if (ind==-1){
ind=window.eventList.length;
window.eventList[ind]=obj;
}
setTimeout("GoOn(" + ind + ")",iMinSecond);
} function GoOn(ind){
var obj=window.eventList[ind];
window.eventList[ind]=null;
if (obj.NextStep) obj.NextStep();
else obj();
} function loadXMLDoc(url)
{
// code for Mozilla, etc.
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest()
xmlhttp.onreadystatechange=xmlhttpChange
xmlhttp.open("GET",url,true)
xmlhttp.send(null)
}
// code for IE
else if (window.ActiveXObject)
{
alert('right');
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
if (xmlhttp)
{
xmlhttp.onreadystatechange=xmlhttpChange
xmlhttp.open("GET",url,true)
xmlhttp.send()
alert('right'); // when code run to here, you should be wait until the source loaded into client side. I don't know how to sleep here in javascripts.
alert (xmlhttp.responseText);
document.write(xmlhttp.responseText);
}
}
}function xmlhttpChange()
{
if (xmlhttp.readyState==4)
{
if (xmlhttp.status==200)
{
}
else
{
}
}
}</script> <HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY onload = ''>
<input type = button name = button value = button onclick = 'loadXMLDoc("http://xxxx.xxxx.xxxx.xxx.js");'>
</BODY>
</HTML>
<script language = javascript>
</script>的.那么这个js文件就是错误的!无论谁用都是错误的,也不可能是什么“网络资源”
问题按你的办法解决了.谢谢各位的参与.