问题是这样的  lz想要在网页上放一个导航栏,点击可以展开显示细节的那种 于是在网上搜了一个比较合适的:
<!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>CSS制作滑动折叠的文字效果 网页设计手册 www.websbook.com</title>
</head>
<style type="text/css">
<!--
body,div,ul,li,p,h1,h2{ margin:0; padding:0; border:0; background:#FAFAFA; font-family:Arial, Helvetica, sans-serif,"宋体"}
body{ text-align:center; font-size:12px}
li{ list-style:none}
.rolinList{ width:402px; height:auto; margin:20px auto 0 auto; text-align:left}
.rolinList li{margin-bottom:1px;border:1px solid #DADADA}
.rolinList li h2{ width:380px; height:40px;  background:#fff; font-size:14px; line-height:40px; padding-left:20px; color:#333; cursor:pointer}
.content{ height:150px;width:400px;  background:#fff;  background:#FAFAFA}
.content p{ margin:12px}
-->
</style><script type="text/javascript">
//<![CDATA[
window.onload = function() {
rolinTab("rolin")
}
function rolinTab(obj) {
var list = $(obj).getElementsByTagName("LI");
var state = {show:false,hidden:false,showObj:false};
for (var i=0; i<list.length; i++) {
var tmp = new rolinItem(list[i],state);
if (i == 0) tmp.pShow();
}
}
function rolinItem(obj,state) {
var speed = 0.0666;
var range = 1;
var interval;
var tarH;
var tar = this;
var head = getFirstChild(obj);
var content = getNextChild(head);
var isOpen = false;
this.pHidden = function() {
if (isOpen) hidden();
}
this.pShow = show;
var baseH = content.offsetHeight;
content.style.display = "none";
var isOpen = false;
head.onmouseover = function() {
this.style.background = "#EFEFEF";
}
head.onmouseout = mouseout;
head.onclick = function() {
this.style.background = "#EFEFEF";
if (!state.show && !state.hidden) {
if (!isOpen) {
head.onmouseout = null;
show();
} else {
hidden();
}
}
}
function mouseout() {
this.style.background = "#FFF"
}
function show() {
head.style.borderBottom = "1px solid #DADADA";
state.show = true;
if (state.openObj && state.openObj != tar ) {
state.openObj.pHidden();
}
content.style.height = "0px";
content.style.display = "block";
content.style.overflow = "hidden";
state.openObj = tar;
tarH = baseH;
interval = setInterval(move,10);
}
function showS() {
isOpen = true;
state.show = false;
}
function hidden() {
state.hidden = true;
tarH = 0;
interval = setInterval(move,10);
}
function hiddenS() {
head.style.borderBottom = "none";
head.onmouseout = mouseout;
head.onmouseout();
content.style.display = "none";
isOpen = false;
state.hidden = false;
}
function move() {
var dist = (tarH - content.style.height.pxToNum())*speed;
if (Math.abs(dist) < 1) dist = dist > 0 ? 1: -1;
content.style.height = (content.style.height.pxToNum() + dist) + "px";
if (Math.abs(content.style.height.pxToNum() - tarH) <= range ) {
clearInterval(interval);
content.style.height = tarH + "px";
if (tarH != 0) {
showS()
} else {
hiddenS();
}
}
}
}
var $ = function($) {return document.getElementById($)};
String.prototype.pxToNum = function() {return Number(this.replace("px",""))}
function getFirstChild(obj) {
var result = obj.firstChild;
while (!result.tagName) {
result = result.nextSibling;
}
return result;
}
function getNextChild(obj) {
var result = obj.nextSibling;
while (!result.tagName) {
result = result.nextSibling;
}
return result;
}
//]]>
</script>
<body>
<ul class="rolinList" id="rolin">
<li>
<h2>网页设计手册 www.websbook.com</h2>
<div class="content"><p>域名:<br /><br />
网页设计手册论坛http://bbs.websbook.com<br />
网页设计手册团队博客http://blog.websbook.com<br />
网页设计手册首页 <br />
我们致力于为中文网站提供动力</p></div>
</li>
<li>
<h2>网页设计手册 websbook.com</h2>
<div class="content"><p>域名:www.cnidc.com<br />
网页设计师与建站爱好者之家, <br />
网页设计师与建站爱好者之家, <br />
网页设计师与建站爱好者之家, <br />
网页设计师与建站爱好者之家</p></div>
</li>
<li>
<h2>网页设计手册 websbook.com </h2>
<div class="content"><p>网页设计师与建站爱好者之家,<br />
网页设计师与建站爱好者之家,<br />
网页设计师与建站爱好者之家,<br />
网页设计师与建站爱好者之家 websbook.COM</p></div>
</li>
<li>
<h2>网页设计手册论坛</h2>
<div class="content"><p>bbs.websbook.com <br />
网页设计师与建站爱好者之家,<br />
网页设计师与建站爱好者之家、<br />
网页设计师与建站爱好者之家、<br />
网页设计师与建站爱好者之家。</p>
</div>
</li>
<li>
<h2>网页设计手册 www.websbook.com</h2>
<div class="content"><p>域名:<br /><br />
网页设计手册论坛http://bbs.websbook.com<br />
网页设计手册首页<br />
网页设计手册首页 <br />
网页设计师与建站爱好者之家</p></div>
</li>
<li>
<h2>网页设计手册论坛</h2>
<div class="content"><p>bbs.websbook.com <br />
网页设计师与建站爱好者之家,<br />
网页设计师与建站爱好者之家、<br />
网页设计师与建站爱好者之家、<br />
网页设计师与建站爱好者之家。</p>
</div>
</li>
</ul>
</body>
</html>
然后 lz希望点击下面展开的细节(上例中就是那些网页设计师与建站爱好者之家的文字) 然后右边的iframe进行切换 于是我又在网上找了一个切换iframe的代码 单独运行没有问题  我发现它是在body里面的 但是如果放在header里面iframe的位置就会乱 所以lz放到body里面了  :
<html>
<head>
<title>Js控制 iFrame 切换加载网址</title>
</head>
<body>
<a href="javascript:jumpto('http://www.163.com')">网易</a> | 
<a href="javascript:jumpto('http://www.baidu.com')">百度搜索</a> | 
<a href="javascript:jumpto('http://www.skycn.com')">软件下载</a> | 
<script language="javascript">
<!--
var displaymode=0
var iframecode='<iframe id="external" style="width:95%;height:388px" src="http://www.codefans.net/jscss/"></iframe>'
if (displaymode==0)
document.write(iframecode)
function jumpto(inputurl){
if (document.getElementById&&displaymode==0)
document.getElementById("external").src=inputurl
else if (document.all&&displaymode==0)
document.all.external.src=inputurl
else{
if (!window.win2||win2.closed)
win2=window.open(inputurl)
else{
win2.location=inputurl
win2.focus()
}
}
}
//-->
</script>
</body>
</html>两端代码单独都可以运行 可以存成html试的 移植之后代码里面一些东西已经改过了 如id什么的 然后两个一起用 就只有后面切换iframe的代码可以用了  前面的导航栏效果消失 所有栏全部是展开效果  why??    怎么让多个js在同一个网页里面相安无事,lz之前本来还想让这个导航栏浮动的(就是位置固定下拉网页还能看到) 搞了一个浮动的代码 单独可以运行 放到一起就悲剧了  当时想是因为两端代码都作用一个对象 可能冲突了  但是上面两端代码作用的是不用的东西啊。。

解决方案 »

  1.   

    <!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>CSS制作滑动折叠的文字效果 网页设计手册 www.websbook.com</title>
    </head>
    <style type="text/css">
    <!--
    body,div,ul,li,p,h1,h2{ margin:0; padding:0; border:0; background:#FAFAFA; font-family:Arial, Helvetica, sans-serif,"宋体"}
    body{ text-align:center; font-size:12px}
    li{ list-style:none}
    .rolinList{ width:402px; height:auto; margin:20px auto 0 auto; text-align:left}
    .rolinList li{margin-bottom:1px;border:1px solid #DADADA}
    .rolinList li h2{ width:380px; height:40px;  background:#fff; font-size:14px; line-height:40px; padding-left:20px; color:#333; cursor:pointer}
    .content{ height:150px;width:400px;  background:#fff;  background:#FAFAFA}
    .content p{ margin:12px}
    -->
    </style><script type="text/javascript">
    //<![CDATA[
    window.onload = function() {
    rolinTab("rolin")
    }
    function rolinTab(obj) {
    var list = $(obj).getElementsByTagName("LI");
    var state = {show:false,hidden:false,showObj:false};
    for (var i=0; i<list.length; i++) {
    var tmp = new rolinItem(list[i],state);
    if (i == 0) tmp.pShow();
    }
    }
    function rolinItem(obj,state) {
    var speed = 0.0666;
    var range = 1;
    var interval;
    var tarH;
    var tar = this;
    var head = getFirstChild(obj);
    var content = getNextChild(head);
    var isOpen = false;
    this.pHidden = function() {
    if (isOpen) hidden();
    }
    this.pShow = show;
    var baseH = content.offsetHeight;
    content.style.display = "none";
    var isOpen = false;
    head.onmouseover = function() {
    this.style.background = "#EFEFEF";
    }
    head.onmouseout = mouseout;
    head.onclick = function() {
    this.style.background = "#EFEFEF";
    if (!state.show && !state.hidden) {
    if (!isOpen) {
    head.onmouseout = null;
    show();
    } else {
    hidden();
    }
    }
    }
    function mouseout() {
    this.style.background = "#FFF"
    }
    function show() {
    head.style.borderBottom = "1px solid #DADADA";
    state.show = true;
    if (state.openObj && state.openObj != tar ) {
    state.openObj.pHidden();
    }
    content.style.height = "0px";
    content.style.display = "block";
    content.style.overflow = "hidden";
    state.openObj = tar;
    tarH = baseH;
    interval = setInterval(move,10);
    }
    function showS() {
    isOpen = true;
    state.show = false;
    }
    function hidden() {
    state.hidden = true;
    tarH = 0;
    interval = setInterval(move,10);
    }
    function hiddenS() {
    head.style.borderBottom = "none";
    head.onmouseout = mouseout;
    head.onmouseout();
    content.style.display = "none";
    isOpen = false;
    state.hidden = false;
    }
    function move() {
    var dist = (tarH - content.style.height.pxToNum())*speed;
    if (Math.abs(dist) < 1) dist = dist > 0 ? 1: -1;
    content.style.height = (content.style.height.pxToNum() + dist) + "px";
    if (Math.abs(content.style.height.pxToNum() - tarH) <= range ) {
    clearInterval(interval);
    content.style.height = tarH + "px";
    if (tarH != 0) {
    showS()
    } else {
    hiddenS();
    }
    }
    }
    }
    var $ = function($) {return document.getElementById($)};
    String.prototype.pxToNum = function() {return Number(this.replace("px",""))}
    function getFirstChild(obj) {
    var result = obj.firstChild;
    while (!result.tagName) {
    result = result.nextSibling;
    }
    return result;
    }
    function getNextChild(obj) {
    var result = obj.nextSibling;
    while (!result.tagName) {
    result = result.nextSibling;
    }
    return result;
    }
    //]]>
    </script>
    <body>
    <ul class="rolinList" id="rolin">
    <li>
    <h2>网页设计手册 www.websbook.com</h2>
    <div class="content"><p>域名:<br /><br />
    网页设计手册论坛http://bbs.websbook.com<br />
    网页设计手册团队博客http://blog.websbook.com<br />
    网页设计手册首页 <br />
    我们致力于为中文网站提供动力</p></div>
    </li>
    <li>
    <h2>网页设计手册 websbook.com</h2>
    <div class="content"><p>域名:www.cnidc.com<br />
    网页设计师与建站爱好者之家, <br />
    网页设计师与建站爱好者之家, <br />
    网页设计师与建站爱好者之家, <br />
    网页设计师与建站爱好者之家</p></div>
    </li>
    <li>
    <h2>网页设计手册 websbook.com </h2>
    <div class="content"><p>网页设计师与建站爱好者之家,<br />
    网页设计师与建站爱好者之家,<br />
    网页设计师与建站爱好者之家,<br />
    网页设计师与建站爱好者之家 websbook.COM</p></div>
    </li>
    <li>
    <h2>网页设计手册论坛</h2>
    <div class="content"><p>bbs.websbook.com <br />
    网页设计师与建站爱好者之家,<br />
    网页设计师与建站爱好者之家、<br />
    网页设计师与建站爱好者之家、<br />
    网页设计师与建站爱好者之家。</p>
    </div>
    </li>
    <li>
    <h2>网页设计手册 www.websbook.com</h2>
    <div class="content"><p>域名:<br /><br />
    网页设计手册论坛http://bbs.websbook.com<br />
    网页设计手册首页<br />
    网页设计手册首页 <br />
    网页设计师与建站爱好者之家</p></div>
    </li>
    <li>
    <h2>网页设计手册论坛</h2>
    <div class="content"><p>bbs.websbook.com <br />
    网页设计师与建站爱好者之家,<br />
    网页设计师与建站爱好者之家、<br />
    网页设计师与建站爱好者之家、<br />
    网页设计师与建站爱好者之家。</p>
    </div>
    </li>
    </ul>
    <a href="javascript:jumpto('http://www.163.com')">网易</a> | 
    <a href="javascript:jumpto('http://www.baidu.com')">百度搜索</a> | 
    <a href="javascript:jumpto('http://www.skycn.com')">软件下载</a> | 
    </body>
    <script>
    <!--
    var displaymode=0
    var iframecode='<iframe id="external" style="width:95%;height:388px" src="http://www.codefans.net/jscss/"></iframe>'
    if (displaymode==0)
    document.write(iframecode)
    function jumpto(inputurl){
    if (document.getElementById&&displaymode==0)
    document.getElementById("external").src=inputurl
    else if (document.all&&displaymode==0)
    document.all.external.src=inputurl
    else{
    if (!window.win2||win2.closed)
    win2=window.open(inputurl)
    else{
    win2.location=inputurl
    win2.focus()
    }
    }
    }
    //--></script>
    </html>楼主看看,是这效果吗?
      

  2.   


    <!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>CSS制作滑动折叠的文字效果 网页设计手册 www.websbook.com</title>
    </head>
    <style type="text/css">
    <!--
    body,div,ul,li,p,h1,h2{ margin:0; padding:0; border:0; background:#FAFAFA; font-family:Arial, Helvetica, sans-serif,"宋体"}
    body{ text-align:center; font-size:12px}
    li{ list-style:none}
    .rolinList{ width:402px; height:auto; margin:20px auto 0 auto; text-align:left}
    .rolinList li{margin-bottom:1px;border:1px solid #DADADA}
    .rolinList li h2{ width:380px; height:40px;  background:#fff; font-size:14px; line-height:40px; padding-left:20px; color:#333; cursor:pointer}
    .content{ height:150px;width:400px;  background:#fff;  background:#FAFAFA}
    .content p{ margin:12px}
    -->
    </style>
    <body>
    <ul class="rolinList" id="rolin">
    <li>
    <h2>网页设计手册 www.websbook.com</h2>
    <div class="content"><p>域名:<br /><br />
    网页设计手册论坛http://bbs.websbook.com<br />
    网页设计手册团队博客http://blog.websbook.com<br />
    网页设计手册首页 <br />
    我们致力于为中文网站提供动力</p></div>
    </li>
    <li>
    <h2>网页设计手册 websbook.com</h2>
    <div class="content"><p>域名:www.cnidc.com<br />
    网页设计师与建站爱好者之家, <br />
    网页设计师与建站爱好者之家, <br />
    网页设计师与建站爱好者之家, <br />
    网页设计师与建站爱好者之家</p></div>
    </li>
    <li>
    <h2>网页设计手册 websbook.com </h2>
    <div class="content"><p>网页设计师与建站爱好者之家,<br />
    网页设计师与建站爱好者之家,<br />
    网页设计师与建站爱好者之家,<br />
    网页设计师与建站爱好者之家 websbook.COM</p></div>
    </li>
    <li>
    <h2>网页设计手册论坛</h2>
    <div class="content"><p>bbs.websbook.com <br />
    网页设计师与建站爱好者之家,<br />
    网页设计师与建站爱好者之家、<br />
    网页设计师与建站爱好者之家、<br />
    网页设计师与建站爱好者之家。</p>
    </div>
    </li>
    <li>
    <h2>网页设计手册 www.websbook.com</h2>
    <div class="content"><p>域名:<br /><br />
    网页设计手册论坛http://bbs.websbook.com<br />
    网页设计手册首页<br />
    网页设计手册首页 <br />
    网页设计师与建站爱好者之家</p></div>
    </li>
    <li>
    <h2>网页设计手册论坛</h2>
    <div class="content"><p>bbs.websbook.com <br />
    网页设计师与建站爱好者之家,<br />
    网页设计师与建站爱好者之家、<br />
    网页设计师与建站爱好者之家、<br />
    网页设计师与建站爱好者之家。</p>
    </div>
    </li>
    </ul>
    <script type="text/javascript">
    //<![CDATA[function rolinTab(obj) {
    var list = $(obj).getElementsByTagName("LI");
    var state = {show:false,hidden:false,showObj:false};
    for (var i=0; i<list.length; i++) {
    var tmp = new rolinItem(list[i],state);
    if (i == 0) tmp.pShow();
    }
    }
    function rolinItem(obj,state) {
    var speed = 0.0666;
    var range = 1;
    var interval;
    var tarH;
    var tar = this;
    var head = getFirstChild(obj);
    var content = getNextChild(head);
    var isOpen = false;
    this.pHidden = function() {
    if (isOpen) hidden();
    }
    this.pShow = show;
    var baseH = content.offsetHeight;
    content.style.display = "none";
    var isOpen = false;
    head.onmouseover = function() {
    this.style.background = "#EFEFEF";
    }
    head.onmouseout = mouseout;
    head.onclick = function() {
    this.style.background = "#EFEFEF";
    if (!state.show && !state.hidden) {
    if (!isOpen) {
    head.onmouseout = null;
    show();
    } else {
    hidden();
    }
    }
    }
    function mouseout() {
    this.style.background = "#FFF"
    }
    function show() {
    head.style.borderBottom = "1px solid #DADADA";
    state.show = true;
    if (state.openObj && state.openObj != tar ) {
    state.openObj.pHidden();
    }
    content.style.height = "0px";
    content.style.display = "block";
    content.style.overflow = "hidden";
    state.openObj = tar;
    tarH = baseH;
    interval = setInterval(move,10);
    }
    function showS() {
    isOpen = true;
    state.show = false;
    }
    function hidden() {
    state.hidden = true;
    tarH = 0;
    interval = setInterval(move,10);
    }
    function hiddenS() {
    head.style.borderBottom = "none";
    head.onmouseout = mouseout;
    head.onmouseout();
    content.style.display = "none";
    isOpen = false;
    state.hidden = false;
    }
    function move() {
    var dist = (tarH - content.style.height.pxToNum())*speed;
    if (Math.abs(dist) < 1) dist = dist > 0 ? 1: -1;
    content.style.height = (content.style.height.pxToNum() + dist) + "px";
    if (Math.abs(content.style.height.pxToNum() - tarH) <= range ) {
    clearInterval(interval);
    content.style.height = tarH + "px";
    if (tarH != 0) {
    showS()
    } else {
    hiddenS();
    }
    }
    }
    }
    var $ = function($) {return document.getElementById($)};
    String.prototype.pxToNum = function() {return Number(this.replace("px",""))}
    function getFirstChild(obj) {
    var result = obj.firstChild;
    while (!result.tagName) {
    result = result.nextSibling;
    }
    return result;
    }
    function getNextChild(obj) {
    var result = obj.nextSibling;
    while (!result.tagName) {
    result = result.nextSibling;
    }
    return result;
    }rolinTab("rolin");
    //]]>
    </script>
    <a href="javascript:jumpto('http://www.163.com')">网易</a> | 
    <a href="javascript:jumpto('http://www.baidu.com')">百度搜索</a> | 
    <a href="javascript:jumpto('http://www.skycn.com')">软件下载</a> | 
    <iframe id="external" style="width:95%;height:388px" src="http://www.codefans.net/jscss/"></iframe>
    <script language="javascript">
    <!--
    /*var displaymode=0
    var iframecode='<iframe id="external" style="width:95%;height:388px" src="http://www.codefans.net/jscss/"></iframe>'
    if (displaymode==0)
    document.write(iframecode)*///这样写没有错误,可是感觉有点繁琐
    function jumpto(inputurl){
    if (document.getElementById&&displaymode==0)
    document.getElementById("external").src=inputurl
    else if (document.all&&displaymode==0)
    document.all.external.src=inputurl
    else{
    if (!window.win2||win2.closed)
    win2=window.open(inputurl)
    else{
    win2.location=inputurl
    win2.focus()
    }
    }
    }
    //-->
    </script>
    </body>
    </html>
      

  3.   

    就是提醒楼主几个问题,把第一段的js放到<body>里效果要好点,不然等页面加载完全,才会有效果
    还有代码如果用jquery岂不是更方便?省的自己还要写什么$函数希望楼主注意