帝国论坛帝国网站管理系统交流区模板/标签/插件共享交流[推荐]一个很多人都想要的ajax栏目切换代码 【本版专题贴子】  
 1/4     1 2 3 4 ›› ›|
主题:[推荐]一个很多人都想要的ajax栏目切换代码 [加入收藏夹]   

禾火木风
用户头衔:嘉宾

精华贴   :11
发贴数   :5478
经验值   :14183
注册时间:2006-03-02
信息 搜索 好友 发送悄悄话 精益求精-帝国网站管理系统7.5正式版开源发布】   [第 1 楼]
[推荐]一个很多人都想要的ajax栏目切换代码
目前比较流行的栏目切换方式,各大网站都采用,前段时间有少人问怎么分离出来,在蓝色理想看到这篇文章,转过来

function.js代码

<!--
function getObject(objectId) {
     if(document.getElementById && document.getElementById(objectId)) {
    // W3C DOM
       return document.getElementById(objectId);
     }
     else if (document.all && document.all(objectId)) {
    // MSIE 4 DOM
       return document.all(objectId);
     }
     else if (document.layers && document.layers[objectId]) {
    // NN 4 DOM.. note: this won't find nested layers
       return document.layers[objectId];
     }
     else {
       return false;
    }
}

var responsecont;
var xmlHttp;
var requestType;
var newsstring;

function CreateXMLHttpRequest(){
   // Initialize Mozilla XMLHttpRequest object
   if (window.XMLHttpRequest){
       xmlHttp = new XMLHttpRequest();
   }
   // Initialize for IE/Windows ActiveX version
   else if (window.ActiveXObject) {
       try{
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
       }
       catch (e){
            try{
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e){newsstring = "服务器繁忙,请稍后重新连接!";}
       }
   }
}

function getnews(tagid,x){
   var url = tagid+'_'+x+'.htm';
   requestType = tagid;
   CreateXMLHttpRequest();   
   
   xmlHttp.onreadystatechange = processRequestChange;
   xmlHttp.open("GET", url, true);
   xmlHttp.setRequestHeader("If-Modified-Since","0");
   xmlHttp.send(null);  
}

function processRequestChange(){
   // only if xmlHttp shows "complete"
   if (xmlHttp.readyState == 4){
      // only http 200 to process
      if (window.location.href.indexOf("http")==-1 || xmlHttp.status == 200){         
   newsstring = xmlHttp.responseText;
         //inject centent to tab-pane
            shownews(requestType,newsstring);
      }
   }
}

function shownews(requestType,newsstring){
//<![CDATA[
    responsecont = getObject(requestType+'_cnt');
    responsecont.innerHTML = newsstring;
//]]>
}

function TabNews(tagid,x){
    for (var i=1;i<=7;i+=2) {
         if (i == x) {
            getObject(tagid+i).className="tabactive"+i;
            if(i!=1){
               getObject(tagid+(i-1)).style.display="none";               
               if(i!=7){
                  getObject(tagid+(i+1)).style.display="none";
               }                 
            }
            if(i==1){
               getObject(tagid+"2").style.display="none";
            }
            try{            
               getnews(tagid,i);
            }
            catch(e){
               alert(e);
            }  
        }
        else
        {
            getObject(tagid+i).className="";            
            if(i!=7){
               getObject(tagid+(i+1)).style.display="block";
            }            
        }         
   }
}
//-->



style.css样式


body{ margin: 0;padding: 0;background: #FFF;color: #000;font: normal 12px 宋体,arial,sans-serif;text-align: left;}
div,form,ul,ol,li,span,p {border: 0;margin: 0;padding: 0;}

/*链接样式*/
a:link{color: #000;text-decoration: none;}
a:visited{color: #000;text-decoration: none;}
a:hover{color: #16387C;text-decoration: underline;}

/*清除float*/
.clear{ clear: both; font-size:1px; visibility: hidden; }

/*空格*/
.blank2{font-size: 1px;height: 2px;margin: 0 auto;width: 962px;}
.blank5{font-size: 1px;height: 5px;margin: 0 auto;width: 950px;}
.sblank2{font-size: 1px;height: 2px;margin: 0 auto;width: 100px;}
.sblank3{font-size: 1px;height: 3px;margin: 0 auto;width: 100px;}
.sblank5{font-size: 1px;height: 5px;margin: 0 auto;width: 400px;}
.sblank7{font-size: 1px;height: 7px;margin: 0 auto;width: 400px;}

/*边距*/
.margin-right{margin-right: 6px;}
.margin-right-left{margin-right: 3px; margin-left:3px;}

/*字体颜色*/
.fcborange{color: #F0741A;font: bold 12px arial,sans-serif;}
.fcred{color:#FF0000;}
.fcwhite{color:#FFF;font:normal 13px 宋体,arial,sans-serif;letter-spacing:1px;}

/*新闻标签导航*/
.news_tabsnav{
    background: url(../images/tab_bg.gif) #FFF left top repeat-x;
    border: solid #B0BEC7;
    border-width: 0 1px 0 1px;
    height: 22px;
    margin: 0 auto;
    padding: 0;
    width: 506px;
}

.news_tabsnav .tabsmenu{
    height: 22px;
}

.news_tabsnav .tab_sline {
    padding-top: 3px;
    width: 2px;
}

.news_tabsnav li {
    color: #18397C;
    display: inline;
    float: left;
    font: normal 12px 宋体,arial,sans-serif;
    letter-spacing: 1px;
    list-style-type: none;
    margin: 0;
    padding-top: 4px;
    text-align: center;
    width: 120px;
}

/*导航菜单点击后的样式*/
.news_tabsnav .tabactive1{
    background: url(../images/tab_active1.gif);
    color: #F26400;
    font: bold 12px 宋体,arial,sans-serif;
    height: 18px;
    letter-spacing: 1px;
    padding-top: 4px;
    text-align: center;
    width: 120px;
}

.news_tabsnav .tabactive3{
    background: url(../images/tab_active2.gif);
    color: #F26400;
    font: bold 12px 宋体,arial,sans-serif;
    height: 18px;
    letter-spacing: 1px;
    padding-top: 4px;
    text-align: center;
    width: 120px;
}

.news_tabsnav .tabactive5{
    background: url(../images/tab_active2.gif);
    color: #F26400;
    font: bold 12px 宋体,arial,sans-serif;
    height: 18px;
    letter-spacing: 1px;
    padding-top: 4px;
    text-align: center;
    width: 120px;
}

.news_tabsnav .tabactive7{
    background: url(../images/tab_active2.gif);
    color: #F26400;
    font: bold 12px 宋体,arial,sans-serif;
    height: 18px;
    letter-spacing: 1px;
    padding-top: 4px;
    text-align: center;
    width: 120px;
}

/*最新消息主体*/
.news_content{
    border: solid #B0BEC7;
    border-width: 0 1px 1px 1px;
    margin: 0 auto;
    width: 506px;
}

/*推荐新闻列表*/
.news_list{
    height: 120px;
    margin: 0 auto;
    width: 492px;
}

.news_list img{
    border: 1px solid #9EB1C0;
    float: left;
    height: 115px;
    margin: 0;
    padding: 1px;
    width: 154px;
    cursor: pointer;
}

.news_list .new_top7{
    float: right;
    height: 120px;
    margin: 0;
    width: 325px;
}

.news_list .new_top7 li{
    float: left;
    font: normal 13px 宋体,sans-serif;
    height: 12px;
    letter-spacing: 1px;
    list-style-type: none;
    margin: 0;
    padding: 0 0 5px 0!important;
    padding: 0 0 2px 0;
    width: 322px;
}

.news_list .new_top7 li a:link,a:visited{
    color: #18397C;
}

.news_list .new_top7 li a:hover{
    color: #FF0000;
}

/*LOGO广告*/
.logos{
    margin: 0 auto;
    width: 488px;
    height: 44px;
    padding: 1px !important;
    border: 1px solid #9EB1C0;
}

.logoscnt{
    margin: 0 auto;
    width: 488px;
    height: 31px !important;
    height: 29px;
    padding: 6px 0 7px 0 !important;
    padding: 4px 0 5px 0;
    text-align: center;
    background: url(../images/logos_bg.gif);
}

/*基本信息统计*/
.siteinfo{
    height: 12px;
    letter-spacing: 1px;
    margin: 0 auto;
    padding: 4px 0 4px 0 !important;
    padding: 2px 0 2px 0;
    text-align: center;
    width: 490px;
}



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=utf-8" />
<title>标签导航</title>
<meta name="Author" content="Robert" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="js/function.js"></script>
</head>
<body>
<div class="sblank2"></div>
<div class="news_tabsnav">
               <ul class="tabsmenu">
                  <li class="tabactive1" style="cursor:pointer" id="tab1" onclick="TabNews('tab',1)">推荐信息</li>
                  <li class="tab_sline" style="display:none" id="tab2"><img src="images/tab_sline.gif" alt="分割线" /></li>
                  <li style="cursor:pointer" id="tab3" onclick="TabNews('tab',3)">最新折扣信息</li>
                  <li class="tab_sline" id="tab4"><img src="images/tab_sline.gif" alt="分割线" /></li>
                  <li style="cursor:pointer" id="tab5" onclick="TabNews('tab',5)">最新团够信息</li>
                  <li class="tab_sline" id="tab6"><img src="images/tab_sline.gif" alt="分割线" /></li>
                  <li style="cursor:pointer" id="tab7" onclick="TabNews('tab',7)">最新活动信息</li>
               </ul><div class="clear"></div>      
</div>
<div class="news_content">
                  <div id="tab_cnt">
               <div class="sblank2"></div>
               <div class="news_list">
                    <img src="images/gyy.jpg" alt="推荐图片新闻" width="154" height="115" border="0" />
                    <ul class="new_top7">
                            <li><a href="#">PRG全棉短袖衬衣最后的抢购机抢购机</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖衬衣最后的抢购机抢购机</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖衬衣最后的抢购机抢购机</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖衬衣最后的抢购机抢购机</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖衬衣最后的抢购机抢购机</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖衬衣最后的抢购机抢购机</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖衬衣最后的抢购机抢购机</a> 2006-08-15</li>
                    </ul>
                    <div class="clear"></div>
               </div>
               <div class="sblank2"></div>
               <div class="logos">
                    <div class="logoscnt">
                         <img src="images/clogo.gif" class="margin-right-left" alt="logo" /><img src="images/clogo.gif" class="margin-right-left" alt="logo" /><img src="images/clogo.gif" class="margin-right-left" alt="logo" /><img src="images/clogo.gif" class="margin-right-left" alt="logo" /><img src="images/clogo.gif" class="margin-right-left" alt="logo" />                    
                    </div>
               </div>
               </div>
               <div class="siteinfo">
                  VIP会员共计<span class="fcborange">10200</span>家,今日注册<span class="fcborange">68</span>人,更新<span class="fcborange">5365</span>条信息,当前总在线<span class="fcborange">62400</span>人
               </div>
</div>
<div class="sblank2"></div>
<div class="news_tabsnav">
               <ul class="tabsmenu">
                  <li class="tabactive1" style="cursor:pointer" id="news1" onclick="TabNews('news',1)">华夏资讯推荐</li>
                  <li class="tab_sline" style="display:none" id="news2"><img src="images/tab_sline.gif" alt="分割线" /></li>
                  <li style="cursor:pointer" id="news3" onclick="TabNews('news',3)">华夏动感宝贝</li>
                  <li class="tab_sline" id="news4"><img src="images/tab_sline.gif" alt="分割线" /></li>
                  <li style="cursor:pointer" id="news5" onclick="TabNews('news',5)">华夏动漫世界</li>
                  <li class="tab_sline" id="news6"><img src="images/tab_sline.gif" alt="分割线" /></li>
                  <li style="cursor:pointer" id="news7" onclick="TabNews('news',7)">华夏体育世界</li>
               </ul><div class="clear"></div>      
</div>
<div class="news_content">
                  <div id="news_cnt">
               <div class="sblank2"></div>
               <div class="news_list">
                    <a href="#"><img src="images/pic.jpg" alt="推荐图片新闻" width="154" height="115" border="0" /></a>
                    <ul class="new_top7">
                            <li><a href="#">PRG全棉短袖衬衣最后的抢购机抢购机</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖衬衣最后的抢购机抢购机</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖衬衣最后的抢购机抢购机</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖衬衣最后的抢购机抢购机</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖衬衣最后的抢购机抢购机</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖衬衣最后的抢购机抢购机</a> 2006-08-15</li>
                            <li><a href="#">PRG全棉短袖衬衣最后的抢购机抢购机</a> 2006-08-15</li>
                    </ul>
                    <div class="clear"></div>
               </div>
               <div class="sblank2"></div>
               <div class="logos">
                    <div class="logoscnt">
                         <img src="images/clogo.gif" class="margin-right-left" alt="logo" /><img src="images/clogo.gif" class="margin-right-left" alt="logo" /><img src="images/clogo.gif" class="margin-right-left" alt="logo" /><img src="images/clogo.gif" class="margin-right-left" alt="logo" /><img src="images/clogo.gif" class="margin-right-left" alt="logo" />                    
                    </div>
               </div>
               </div>
               <div class="siteinfo">
                  VIP会员共计<span class="fcborange">10200</span>家,今日注册<span class="fcborange">68</span>人,更新<span class="fcborange">5365</span>条信息,当前总在线<span class="fcborange">62400</span>人
               </div>
</div>
</body>
</html>



效果演示:http://jc.fc510.com/files/tab/index.htm

效果图:

上传以下图片:


[该贴被修改 2 次,最后修改时间 2006-10-23 22:23:31 ]


梦想设计 成就你的设计梦想
2006-10-23 22:21:45 已设置保密 顶部 回复 引用 报告 编辑 删除

pppaaa
用户头衔:举人

精华贴   :0
发贴数   :161
经验值   :969
注册时间:2006-02-08
信息 搜索 好友 发送悄悄话 免费开源-EBMA系统:更安全的MYSQL管理和备份系统】   [第 2 楼]

你根据你的css样式,再结合你的模板改一下发给大家行吗?!




2006-10-23 23:16:49 已设置保密 顶部 回复 引用 报告 编辑 删除

城市童话
用户头衔:举人

精华贴   :0
发贴数   :489
经验值   :1546
注册时间:2005-11-30
信息 搜索 好友 发送悄悄话 精益求精-帝国网站管理系统7.5正式版开源发布】   [第 3 楼]

牛..............此贴加分.




2006-10-23 23:26:39 已设置保密 顶部 回复 引用 报告 编辑 删除

wm_chief
用户头衔:管理员

精华贴   :21
发贴数   :48941
经验值   :114161
注册时间:2002-10-30
信息 搜索 好友 发送悄悄话 免费开源-EBMA系统:更安全的MYSQL管理和备份系统】   [第 4 楼]

不错。以后可用到



[零基础入门教程] [模板制作教程] [采集使用教程]
2006-10-24 08:08:47 已设置保密 顶部 回复 引用 报告 编辑 删除

忧郁浪子
用户头衔:举人

精华贴   :0
发贴数   :329
经验值   :1002
注册时间:2006-06-27
信息 搜索 好友 发送悄悄话 精益求精-帝国网站管理系统7.5正式版开源发布】   [第 5 楼]

CSS可以实现这种效果吧?




2006-10-24 09:32:02 已设置保密 顶部 回复 引用 报告 编辑 删除

晴天
用户头衔:书生

精华贴   :0
发贴数   :7
经验值   :35
注册时间:2006-10-24
信息 搜索 好友 发送悄悄话 免费开源-EBMA系统:更安全的MYSQL管理和备份系统】   [第 6 楼]

晕,好像不行呀...




2006-10-24 16:02:40 已设置保密 顶部 回复 引用 报告 编辑 删除

ansky
用户头衔:秀才

精华贴   :0
发贴数   :85
经验值   :351
注册时间:2005-11-10
信息 搜索 好友 发送悄悄话 精益求精-帝国网站管理系统7.5正式版开源发布】   [第 7 楼]

帅,好帖顶之




2006-10-24 16:35:12 已设置保密 顶部 回复 引用 报告 编辑 删除

1ling
用户头衔:进士 *

精华贴   :2
发贴数   :621
经验值   :2661
注册时间:2005-12-31
信息 搜索 好友 发送悄悄话 免费开源-EBMA系统:更安全的MYSQL管理和备份系统】   [第 8 楼]

好东西啊,太谢谢楼主了



帝国CMS站长之家 UI设计
2006-10-24 18:22:26 已设置保密 顶部 回复 引用 报告 编辑 删除

dzlqsq
用户头衔:进士

精华贴   :0
发贴数   :917
经验值   :3748
注册时间:2006-08-31
信息 搜索 好友 发送悄悄话 精益求精-帝国网站管理系统7.5正式版开源发布】   [第 9 楼]

晕,好像不行呀...


搂主,你的html代码应该不全的吧,,最好演示页能打包提供下载。这样下来运行就能看到效果!!



欢迎来我的鸟站看看www.51107.net
2006-10-24 20:59:16 已设置保密 顶部 回复 引用 报告 编辑 删除

晴天
用户头衔:书生

精华贴   :0
发贴数   :7
经验值   :35
注册时间:2006-10-24
信息 搜索 好友 发送悄悄话 免费开源-EBMA系统:更安全的MYSQL管理和备份系统】   [第 10 楼]



搂主,你的html代码应该不全的吧,,最好演示页能打包提供下载。这样下来运行就能看到效果!!



就是哟.....




2006-10-24 22:27:45 已设置保密 顶部 回复 引用 报告 编辑 删除
 1/4     1 2 3 4 ›› ›|

快速回复
内容

表情
使用EBB代码 使用smile代码 显示签名 自动分析url 自动分析img
     【进入高级模式】   (按 Ctrl+Enter 直接提交)
    顶部  加入收藏夹
关于帝国 | 广告服务 | 联系我们 | 法律声明 | 隐私条款 | 许可协议
Powered by: EBB Version 2.2.1