在IE中,利用 eval(idName) 可以取得 id 为 idName 的 HTML 对象,在MF 中不能。
解决方法
用 getElementById(idName) 代替 eval(idName)。
解决方法
用 getElementById(idName) 代替 eval(idName)。
解决方案 »
- 求JS特效:首页是从左到右的滚动的图片缩略图(绑定到数据库) 点击进入后是图片列表 怎么实现啊
- 求JS的几张图片切换代码,在IE下和firefox都可以用。。在线等,谢谢
- 请教一个页面多个checkbox的控制选择问题~!!!
- innerHTML问题,急!!!(高分求解)
- 请问JavaScript有何方法修改IE的文字大小设置
- 求救一个DIV块的坐标问题,
- javascript传递参数的问题,高分求救!很急,各位帮忙呀!
- cpplus(百合):<select id="select1" onChange="addItem()">如果是name而不是id怎么办?
- <select>控件的关联
- js 导入问题
- 如何使用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';