麻烦各位看个这么一段JS代码 getElementById() 不能返回对象集合.getElementsByName() 才可以.但是<div>标签没有name属性的. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 replycount = reply.length; 是这个replycount = reply.innerHTML.length;? 变通一下处理:<!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 onload="GetReply()"><script type="text/javascript"> var replycount = 0; function GetReply() { var replys = document.getElementsByTagName("div"); for(var i = 0;i < replys.length;i++) if(replys[i].id == "reply") replycount++ alert(replycount); } function Show(aid) { for ( i=0 ; i <replycount ; i++ ) { if(aid==i) reply[aid].style.display=""; else reply[i].style.display="none"; } } </script> <form> <div id="book1">留言1内容 <a href="#" id="0" onMouseMove="Show(this.id)">回复 </a> </div> <div id="reply" style="display:none">回复1 </div> <div id="book2">留言2内容 <a href="#" id="1" onMouseMove="Show(this.id)">回复 </a> </div> <div id="reply" style="display:none">回复2 </div> </form> </body></html> <html><head><meta http-equiv="Content-Type" content="text/html; charset=shift_jis"><title>新しいページ 1</title><script type="text/javascript"> var replycount; function GetReply() { var reply = document.getElementById("reply");alert(reply.innerHTML) replycount = reply.length; alert(replycount); } function Show(aid) { for ( i=0 ; i <replycount ; i++ ) { if(aid==i) reply[aid].style.display=""; else reply[i].style.display="none"; } } </script> <BODY onload="GetReply()"> <form> <div id="book1">留言1内容 <a href="#" id="0" onMouseMove="Show(this.id)">回复 </a> </div> <div id="reply">1 </div> <div id="book2">留言2内容 <a href="#" id="1" onMouseMove="Show(this.id)">回复 </a> </div> <div id="reply">2 </div> </form> </BODY>你看看这个就明白了 哥们问题还没解决function Show(aid) { for ( a=0 ; a <replycount ; a++ ) { if(aid==a) { reply[aid].style.display=""; document.getElementById("book" + aid).style.display="none"; }else{ reply[a].style.display="none"; } } } 我的意思是说 <div id="book1">留言1内容<a href="#" id="0" onMouseMove="Show(this.id)">回复 </a> </div> <div id="reply" style="display:none">回复1 </div> <div id="book2">留言2内容 <a href="#" id="1" onMouseMove="Show(this.id)">回复 </a> </div> <div id="reply" style="display:none">回复2 </div> 当鼠标放到 “回复”上的时候这个时候相对应的只显示“回复1” id=book1 的DIV 要隐藏可目前的效果是 “回复1"显示出来了可是 ID=BOOK1 的div 内容也依然存在 看看这个<html><head><script type="text/javascript">function Show(o1,o2){var obj1=document.getElementById(o1);var obj2=document.getElementById(o2);obj1.style.display='none';obj2.style.display='block';}function resetback(ob){document.getElementById(ob).style.display='block';}</script></head><BODY><form><div id="book1" onmouseover="Show('book1','book2');" onmouseout="resetback('book1');">留言1内容 <a href="#" id="0">回复 </a> </div><br><br><br><br><br><br> <div id="book2" onmouseover="Show('book2','book1');" onmouseout="resetback('book2');">留言2内容 <a href="#" id="1">回复 </a> </div></form></BODY></html> 以下测试通过:<!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 onload="GetReply()"><script type="text/javascript"> var replycount = 0; function GetReply() { var replys = document.getElementsByTagName("div"); for(var i = 0;i < replys.length;i++) if(replys[i].id == "reply") replycount++ alert(replycount); } function Show(aid) { for (i = 0;i <replycount;i++) { if(aid==i) { reply[aid].style.display = ""; document.getElementById("book" + (i + 1)).style.display = "none"; } else { reply[i].style.display="none"; document.getElementById("book" + (i + 1)).style.display = ""; } } } </script> <form> <div id="book1">留言1内容 <a href="#" id="0" onMouseMove="Show(this.id)">回复 </a> </div> <div id="reply" style="display:none">回复1 </div> <div id="book2">留言2内容 <a href="#" id="1" onMouseMove="Show(this.id)">回复 </a> </div> <div id="reply" style="display:none">回复2 </div> </form> </body></html> 你的两个DIV靠的太近,感觉不出效果,我加了几个换行。 JS问题 highcharts pie问题! a链接下href属性中写javascript和普通的javascript有没有区别 我想把"360绿色版浏览器"的默认值改为当前目录下的index.htm,可以吗? JavaScript帧窗口问题。没分了 谢谢了。 请教一个js按钮问题 一个 一个表单两个submit按钮 網頁不支持mac機,如何解決? 谁能帮我把这些vbs函数翻译成jscript的方法或函数? 类似range对象surroundContents方法,但能跨标签,怎么实现 我要发疯了!~ 求教:js能否往修改当前浏览页面的属性
是这个
replycount = reply.innerHTML.length;
?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body onload="GetReply()">
<script type="text/javascript">
var replycount = 0;
function GetReply()
{
var replys = document.getElementsByTagName("div");
for(var i = 0;i < replys.length;i++) if(replys[i].id == "reply") replycount++
alert(replycount);
} function Show(aid)
{
for ( i=0 ; i <replycount ; i++ )
{
if(aid==i) reply[aid].style.display="";
else reply[i].style.display="none";
}
}
</script>
<form>
<div id="book1">留言1内容 <a href="#" id="0" onMouseMove="Show(this.id)">回复 </a> </div>
<div id="reply" style="display:none">回复1 </div>
<div id="book2">留言2内容 <a href="#" id="1" onMouseMove="Show(this.id)">回复 </a> </div>
<div id="reply" style="display:none">回复2 </div>
</form>
</body>
</html>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">
<title>新しいページ 1</title>
<script type="text/javascript">
var replycount;
function GetReply()
{
var reply = document.getElementById("reply");
alert(reply.innerHTML)
replycount = reply.length;
alert(replycount);
} function Show(aid)
{
for ( i=0 ; i <replycount ; i++ )
{
if(aid==i)
reply[aid].style.display="";
else
reply[i].style.display="none";
}
}
</script>
<BODY onload="GetReply()">
<form>
<div id="book1">留言1内容 <a href="#" id="0" onMouseMove="Show(this.id)">回复 </a> </div>
<div id="reply">1 </div> <div id="book2">留言2内容 <a href="#" id="1" onMouseMove="Show(this.id)">回复 </a> </div>
<div id="reply">2 </div>
</form>
</BODY>你看看这个
就明白了
问题还没解决function Show(aid)
{
for ( a=0 ; a <replycount ; a++ )
{
if(aid==a)
{
reply[aid].style.display="";
document.getElementById("book" + aid).style.display="none";
}else{
reply[a].style.display="none";
}
}
} 我的意思是说
<div id="book1">留言1内容<a href="#" id="0" onMouseMove="Show(this.id)">回复 </a> </div>
<div id="reply" style="display:none">回复1 </div>
<div id="book2">留言2内容 <a href="#" id="1" onMouseMove="Show(this.id)">回复 </a> </div>
<div id="reply" style="display:none">回复2 </div> 当鼠标放到 “回复”上的时候
这个时候
相对应的只显示“回复1” id=book1 的DIV 要隐藏可目前的效果是 “回复1"显示出来了
可是 ID=BOOK1 的div 内容也依然存在
<head>
<script type="text/javascript">
function Show(o1,o2)
{
var obj1=document.getElementById(o1);
var obj2=document.getElementById(o2);
obj1.style.display='none';
obj2.style.display='block';
}
function resetback(ob){document.getElementById(ob).style.display='block';
}
</script>
</head>
<BODY>
<form>
<div id="book1" onmouseover="Show('book1','book2');" onmouseout="resetback('book1');">留言1内容 <a href="#" id="0">回复 </a> </div>
<br><br><br><br><br><br>
<div id="book2" onmouseover="Show('book2','book1');" onmouseout="resetback('book2');">留言2内容 <a href="#" id="1">回复 </a> </div>
</form>
</BODY>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body onload="GetReply()">
<script type="text/javascript">
var replycount = 0;
function GetReply()
{
var replys = document.getElementsByTagName("div");
for(var i = 0;i < replys.length;i++) if(replys[i].id == "reply") replycount++
alert(replycount);
} function Show(aid)
{
for (i = 0;i <replycount;i++)
{
if(aid==i)
{
reply[aid].style.display = "";
document.getElementById("book" + (i + 1)).style.display = "none";
}
else
{
reply[i].style.display="none";
document.getElementById("book" + (i + 1)).style.display = "";
}
}
}
</script>
<form>
<div id="book1">留言1内容 <a href="#" id="0" onMouseMove="Show(this.id)">回复 </a> </div>
<div id="reply" style="display:none">回复1 </div>
<div id="book2">留言2内容 <a href="#" id="1" onMouseMove="Show(this.id)">回复 </a> </div>
<div id="reply" style="display:none">回复2 </div>
</form>
</body>
</html>