就javascript的显示隐藏问题发表提问 在IE中,利用 eval(idName) 可以取得 id 为 idName 的 HTML 对象,在MF 中不能。 解决方法 用 getElementById(idName) 代替 eval(idName)。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我用楼上的方法改成这样var targetImg =getElementById("followImg" + ino);var targetDiv =getElementById("follow" + ino);可还是没有效果 var targetImg =getElementById["followImg" + ino];var targetDiv =getElementById["follow" + ino];改成这样再试试 菜鸟哦,随便说说var targetImg =document.getElementById("followImg" + ino);var targetDiv =document.getElementById("follow" + ino); 按4楼的写法,另外,不知FF对targetImg.loaded是否支持判断。 非常感谢楼上几位打侠,效果终于出来了。还有个问题,在load.asp 到入的框架页里有一句这样的javascript 语句。同样在ie 下正常。到了ff就出不了效果了,不知道应该怎么修改,语句如下:<SCRIPT>parent.followImg<%=id%>.loaded="yes";parent.followTd<%=id%>.innerHTML='<table width=100% cellpadding=10 style=TABLE-LAYOUT:fixed><tr><td width=100% style=WORD-WRAP:break-word class=style13><%=content%></td></tr></table>';</SCRIPT>在论坛上找到这个方法可是不知道怎么下手innerHTML的区别 Firefox不支持innerHTML, 解决办法可以如下 rng = document.createRange(); el = document.getElementById(elementid); rng.setStartBefore(el); htmlFrag = rng.createContextualFragment(content); while (el.hasChildNodes()) //清除原有内容,加入新内容 el.removeChild(el.lastChild); el.appendChild(htmlFrag); Firefox 不支持innerHTML ?????谁给讲解一下 有哪位高人在浏览器上处理过innerHTML 的问题吗? 我这样改在firefox里还是实现不了载入load.asp页的效果,不知道哪位做过这方面请教一下<SCRIPT>parent.document.getElementById(followImg<%=id%>).loaded="yes";parent.document.getElementById(followTd<%=id%>).innerHTML='<table width=100% cellpadding=10 style=TABLE-LAYOUT:fixed><tr><td width=100% style=WORD-WRAP:break-word class=style13><%=content%></td></tr></table>';</SCRIPT> <script>if(navigator.userAgent.toLowerCase().indexOf("firefox") != -1)//ff{ parent.document.getElementById(followImg<%=id%>).loaded="yes"; var el=parent.document.getElementById(followTd<%=id%>); rng = document.createRange(); rng.setStartBefore(el); var content='<table width=100% cellpadding=10 style=TABLE-LAYOUT:fixed><tr><td width=100% style=WORD-WRAP:break-word class=style13><%=content%></td></tr></table>'; htmlFrag =rng.createContextualFragment(content); while(el.hasChildNodes()) //清除原有内容,加入新内容 el.removeChild(el.lastChild); el.appendChild(htmlFrag);}if(window.ActiveXObject)//IE{ parent.document.getElementById(followImg<%=id%>).loaded="yes";parent.document.getElementById(followTd<%=id%>).innerHTML='<table width=100% cellpadding=10 style=TABLE-LAYOUT:fixed><tr><td width=100% style=WORD-WRAP:break-word class=style13><%=content%></td></tr></table>';} ff好象老的版本不支持innerHTML,新版本支持innerHTML我用的2.0的就没问题,但是哪个版本以前的用不了就不太清楚了 我用了aaron81939097 的方法结果在ie 和 ff里还是实现不了效果啊。parent.document.getElementById(followImg <%=id%> ).loaded="yes"; parent.document.getElementById(followTd <%=id%> ).innerHTML=' <table width=100% cellpadding=10 style=TABLE-LAYOUT:fixed> <tr> <td width=100% style=WORD-WRAP:break-word class=style13> <%=content%> </td> </tr> </table> '; 这句我放在ie里试过得不出内容的 parent.document.getElementById("followImg"+"+<%=id%>+").loaded="yes"; parent.document.getElementById("followTd"+"+<%=id%>+").innerHTML=' <table width=100% cellpadding=10 style=TABLE-LAYOUT:fixed> <tr> <td width=100% style=WORD-WRAP:break-word class=style13> <%=content%> </td> </tr> </table> '; 这样再试 根据 aaron81939097 的思路 我改成这样parent.document.getElementById("followImg<%=id%>").loaded="yes"; parent.document.getElementById("followTd<%=id%>").innerHTML='<table width=100% cellpadding=10 style=TABLE-LAYOUT:fixed><tr><td width=100% style=WORD-WRAP:break-word class=style13><%=content%></td></tr></table>'; 结果是在ie里 能够正常得出load.asp 的内容。但在ff里 还是得不出结果我在ff里是这样修改:if(navigator.userAgent.toLowerCase().indexOf("firefox") != -1)//ff { parent.document.getElementById("followImg<%=id%>").loaded="yes"; var el=parent.document.getElementById("followTd<%=id%>"); rng = document.createRange(); rng.setStartBefore(el); var content='<table width=100% cellpadding=10 style=TABLE-LAYOUT:fixed><tr><td width=100% style=WORD-WRAP:break-word class=style13><%=content%></td></tr></table>'; htmlFrag =rng.createContextualFragment(content); while(el.hasChildNodes()) //清除原有内容,加入新内容 el.removeChild(el.lastChild); el.appendChild(htmlFrag); } if(window.ActiveXObject)//IE { parent.document.getElementById("followImg<%=id%>").loaded="yes"; parent.document.getElementById("followTd<%=id%>").innerHTML='<table width=100% cellpadding=10 style=TABLE-LAYOUT:fixed><tr><td width=100% style=WORD-WRAP:break-word class=style13><%=content%></td></tr></table>'; }假如以上代码在load.asp 页里没有错误,那么我调用load.asp的也是不是还有其他不对的地方?调用load.asp页的代码是这样:<table width="43%"><tr><td class=style13 width=41% > <img loaded=no src=images/plus.gif id=followImg5 style=cursor:hand; onclick=loadThreadFollow(5)>aaa <a href=Show.asp?id=5 target=_blank onClick=window.close()>bbb</a></td><td align=middle width=37% class=style13>ccc</td><td width=22% colspan="3" align=middle class=style13>ccc普通</td></tr><tr height=20 style="display:none" id=follow5><td id=followTd5 align=left class=a4 colspan=3> Loading...</td></tr><tr height=1 ><td colspan=5 background=images/line.gif></td></tr></table><script>function loadThreadFollow(ino,online){var targetImg =eval("followImg" + ino);var targetDiv =eval("follow" + ino);if (targetDiv.style.display!='block'){targetDiv.style.display="block";targetImg.src="images/minus.gif";if(targetImg.loaded=="no"){document.frames["hiddenframe"].location.replace("loading.asp?id="+ino+"&forumid="+online+"");}}else{targetDiv.style.display="none";targetImg.src="images/plus.gif";}}document.write("<iframe height=0 width=0 name=hiddenframe class=style13></iframe>")</script>6楼的nicholsky 提到FF对targetImg.loaded是否支持判断。难道这里还有出处吗? IE下可以用document.frames("name").document的方式取得frame中所嵌页面的document对象,FF下却会得到null,解决的的办法是document.getElementById(framename).contentWindow.document,也可以使用window.frames[frameName].document 直接获取frame里的document对象 用window.frames['hiddenframe'].location.replace看看 我用window.frames['hiddenframe'].location.replace 这个方法在ie 里可行,但在ff里还是不能得出结果。改成这个document.getElementsByName("hiddenframe").contentWindow.location.replace 结果在ie 和ff 多不能显示load.asp的内容 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title></head><body><input name="" type="button" value="click" onclick='loadThreadFollow(5)'/><table><tr style="display:none" id='follow5'><td id='followTd5'>123</td></tr></table><script>function loadThreadFollow(i){ var targetDiv =document.getElementById("follow" + i); if (targetDiv.style.display==''){ targetDiv.style.display="none"; }else{ targetDiv.style.display=""; window.frames["hiddenframe"].location.replace("loading.asp?id="+i); }}document.write("<iframe height='0' width='0' name='hiddenframe'></iframe>")</script></body></html>loading.asp<script> parent.document.getElementById("followTd<%=request.QueryString("id")%>").innerHTML='321'; </script>我用ff ie7测试貌似没问题你先用这个测试看看 还是不行就用其他方法吧例如<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title></head><body><input name="" type="button" value="click" onclick='loadThreadFollow(5)'/><table><tr style="display:none" id='follow5'><td id='followTd5'>123</td></tr></table><script>function loadThreadFollow(i){ var targetDiv =document.getElementById("follow" + i); if (targetDiv.style.display==''){ targetDiv.style.display="none"; }else{ targetDiv.style.display=""; document.getElementById("a").src = "loading.asp?id="+i+"&"+Math.random(); }}</script><script id="a"></script></body></html>loading.aspdocument.getElementById("followTd5").innerHTML='321'; loading.asp document.getElementById("followTd<%=request.QueryString("id")%>").innerHTML='321'; 终于好了,太感谢cloudgamer 了。 非常感谢。 JS输出DIV的绝对定位 下拉类表框一个不见了 为什么不能动态添加事件监听 jquery怎样增加一个unit? 求正则验证 自动生成的表格如何设置变色 如何刷新另一个框架的页面??谢谢 div中 显示 空白 一个正则表达式,不太理解! 怎样才可以让数组的每个元素都有自己的对象? 如何使用javascript 中的replace来替换\ 不能保存,数组索引越界????
var targetImg =getElementById("followImg" + ino);
var targetDiv =getElementById("follow" + ino);可还是没有效果
var targetDiv =getElementById["follow" + ino];改成这样再试试
var targetDiv =document.getElementById("follow" + ino);
还有个问题,在load.asp 到入的框架页里有一句这样的javascript 语句。同样在ie 下正常。到了ff就出不了效果了,不知道应该怎么修改,语句如下:
<SCRIPT>
parent.followImg<%=id%>.loaded="yes";
parent.followTd<%=id%>.innerHTML='<table width=100% cellpadding=10 style=TABLE-LAYOUT:fixed><tr><td width=100% style=WORD-WRAP:break-word class=style13><%=content%></td></tr></table>';
</SCRIPT>在论坛上找到这个方法可是不知道怎么下手
innerHTML的区别
Firefox不支持innerHTML, 解决办法可以如下
rng = document.createRange();
el = document.getElementById(elementid);
rng.setStartBefore(el);
htmlFrag = rng.createContextualFragment(content);
while (el.hasChildNodes()) //清除原有内容,加入新内容
el.removeChild(el.lastChild);
el.appendChild(htmlFrag);
<SCRIPT>
parent.document.getElementById(followImg<%=id%>).loaded="yes";
parent.document.getElementById(followTd<%=id%>).innerHTML='<table width=100% cellpadding=10 style=TABLE-LAYOUT:fixed><tr><td width=100% style=WORD-WRAP:break-word class=style13><%=content%></td></tr></table>';
</SCRIPT>
if(navigator.userAgent.toLowerCase().indexOf("firefox") != -1)//ff
{
parent.document.getElementById(followImg<%=id%>).loaded="yes";
var el=parent.document.getElementById(followTd<%=id%>);
rng = document.createRange();
rng.setStartBefore(el);
var content='<table width=100% cellpadding=10 style=TABLE-LAYOUT:fixed><tr><td width=100% style=WORD-WRAP:break-word class=style13><%=content%></td></tr></table>';
htmlFrag =rng.createContextualFragment(content);
while(el.hasChildNodes()) //清除原有内容,加入新内容
el.removeChild(el.lastChild);
el.appendChild(htmlFrag);
}
if(window.ActiveXObject)//IE
{
parent.document.getElementById(followImg<%=id%>).loaded="yes";
parent.document.getElementById(followTd<%=id%>).innerHTML='<table width=100% cellpadding=10 style=TABLE-LAYOUT:fixed><tr><td width=100% style=WORD-WRAP:break-word class=style13><%=content%></td></tr></table>';
}
我用的2.0的就没问题,但是哪个版本以前的用不了就不太清楚了
parent.document.getElementById(followTd <%=id%> ).innerHTML=' <table width=100% cellpadding=10 style=TABLE-LAYOUT:fixed> <tr> <td width=100% style=WORD-WRAP:break-word class=style13> <%=content%> </td> </tr> </table> ';
这句我放在ie里试过得不出内容的
parent.document.getElementById("followTd"+"+<%=id%>+").innerHTML=' <table width=100% cellpadding=10 style=TABLE-LAYOUT:fixed> <tr> <td width=100% style=WORD-WRAP:break-word class=style13> <%=content%> </td> </tr> </table> ';
这样再试
parent.document.getElementById("followImg<%=id%>").loaded="yes";
parent.document.getElementById("followTd<%=id%>").innerHTML='<table width=100% cellpadding=10 style=TABLE-LAYOUT:fixed><tr><td width=100% style=WORD-WRAP:break-word class=style13><%=content%></td></tr></table>';
结果是在ie里 能够正常得出load.asp 的内容。但在ff里 还是得不出结果
我在ff里是这样修改:
if(navigator.userAgent.toLowerCase().indexOf("firefox") != -1)//ff
{
parent.document.getElementById("followImg<%=id%>").loaded="yes";
var el=parent.document.getElementById("followTd<%=id%>");
rng = document.createRange();
rng.setStartBefore(el);
var content='<table width=100% cellpadding=10 style=TABLE-LAYOUT:fixed><tr><td width=100% style=WORD-WRAP:break-word class=style13><%=content%></td></tr></table>';
htmlFrag =rng.createContextualFragment(content);
while(el.hasChildNodes()) //清除原有内容,加入新内容
el.removeChild(el.lastChild);
el.appendChild(htmlFrag);
}
if(window.ActiveXObject)//IE
{
parent.document.getElementById("followImg<%=id%>").loaded="yes";
parent.document.getElementById("followTd<%=id%>").innerHTML='<table width=100% cellpadding=10 style=TABLE-LAYOUT:fixed><tr><td width=100% style=WORD-WRAP:break-word class=style13><%=content%></td></tr></table>';
}假如以上代码在load.asp 页里没有错误,那么我调用load.asp的也是不是还有其他不对的地方?调用load.asp页的代码是这样:
<table width="43%"><tr><td class=style13 width=41% > <img loaded=no src=images/plus.gif id=followImg5 style=cursor:hand; onclick=loadThreadFollow(5)>aaa <a href=Show.asp?id=5 target=_blank onClick=window.close()>bbb</a></td>
<td align=middle width=37% class=style13>ccc</td>
<td width=22% colspan="3" align=middle class=style13>ccc普通</td>
</tr>
<tr height=20 style="display:none" id=follow5><td id=followTd5 align=left class=a4 colspan=3> Loading...</td></tr>
<tr height=1 ><td colspan=5 background=images/line.gif></td></tr></table>
<script>
function loadThreadFollow(ino,online){
var targetImg =eval("followImg" + ino);
var targetDiv =eval("follow" + ino);
if (targetDiv.style.display!='block'){
targetDiv.style.display="block";
targetImg.src="images/minus.gif";
if(targetImg.loaded=="no"){document.frames["hiddenframe"].location.replace("loading.asp?id="+ino+"&forumid="+online+"");}
}else{
targetDiv.style.display="none";
targetImg.src="images/plus.gif";
}
}
document.write("<iframe height=0 width=0 name=hiddenframe class=style13></iframe>")
</script>6楼的nicholsky 提到FF对targetImg.loaded是否支持判断。难道这里还有出处吗?
window.frames[frameName].document 直接获取frame里的document对象
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<input name="" type="button" value="click" onclick='loadThreadFollow(5)'/>
<table>
<tr style="display:none" id='follow5'>
<td id='followTd5'>123</td>
</tr>
</table>
<script>
function loadThreadFollow(i){
var targetDiv =document.getElementById("follow" + i);
if (targetDiv.style.display==''){
targetDiv.style.display="none";
}else{
targetDiv.style.display="";
window.frames["hiddenframe"].location.replace("loading.asp?id="+i);
}
}
document.write("<iframe height='0' width='0' name='hiddenframe'></iframe>")
</script></body>
</html>
loading.asp<script>
parent.document.getElementById("followTd<%=request.QueryString("id")%>").innerHTML='321';
</script>
我用ff ie7测试貌似没问题
你先用这个测试看看
例如
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<input name="" type="button" value="click" onclick='loadThreadFollow(5)'/>
<table>
<tr style="display:none" id='follow5'>
<td id='followTd5'>123</td>
</tr>
</table><script>
function loadThreadFollow(i){
var targetDiv =document.getElementById("follow" + i);
if (targetDiv.style.display==''){
targetDiv.style.display="none";
}else{
targetDiv.style.display="";
document.getElementById("a").src = "loading.asp?id="+i+"&"+Math.random();
}
}
</script>
<script id="a"></script>
</body>
</html>loading.aspdocument.getElementById("followTd5").innerHTML='321';