导航栏上有一个“品牌周刊”频道——— 一级;该频道下面又要分“2010中国品牌报”、“2009中国品牌报”等(由用户自己添加)———— 二级;然后二级下又分“2010年12月31日第五期”等(由用户自己添加)————三级三级下面就是其对应的内容了。我该怎么去实现???要用联动类别吗???还是在“网站栏目管理”操作中一个栏目一个栏目的添加,然后再添加子类???

解决方案 »

  1.   


    ajax联动php+ajax实例:php+Ajax二级联动菜单 源码及数据库请到这里下载 
    http://www.haohaoxx8.com/plus/list.php?tid=19,请自行修改数据库连接 本例包括两个文件index.php: 程序代码
    <html>
    <head>
    <title>php+Ajax二级联动菜单</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <style type="text/css">
    <!--
    body {
    background-color: #0099CC;
    }
    -->
    </style></head>
    <script language="javascript">
    var http_request = false;
    function createRequest(url) {
    //初始化对象并发出XMLHttpRequest请求
    http_request = false;
    if (window.XMLHttpRequest) { // Mozilla或其他除IE以外的浏览器
      http_request = new XMLHttpRequest();
      if (http_request.overrideMimeType) {
       http_request.overrideMimeType("text/xml");
      }
    } else if (window.ActiveXObject) { // IE浏览器
      try {
       http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
       try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");     } catch (e) {}
      }
    }
    if (!http_request) {
      alert("不能创建XMLHTTP实例!");
      return false;
    }
    http_request.onreadystatechange = alertContents;    //指定响应方法
    //发出HTTP请求
    http_request.open("GET", url, true);
    http_request.send(null);
    }
    function alertContents() {    //处理服务器返回的信息
    if (http_request.readyState == 4) {
      if (http_request.status == 200) {
       subType.innerHTML=http_request.responseText;
      } else {
       alert('您请求的页面发现错误');
      }
    }}
    </script>
    <script language="javascript">
    function F_super(val){
    createRequest("selSubType.php?type="+val+'&nocache='+new Date().getTime());  //实现级联下拉列表
    }
    </script>
    <script language="javascript">
    function mycheck(){
    if (form1.goodsName.value==""){
      alert("请输入商品名称!");form1.goodsName.focus();return;
    }
    if (form1.picture.value==""){
      alert("请输入图片文件的路径!");form1.picture.focus();return;
    }
    if (form1.price.value==""){
      alert("请输入商品的定价!");form1.price.focus();return;
    }
    if (isNaN(form1.price.value)){
      alert("您输入的定价错误,请重新输入!");form1.price.value="";form1.price.focus();return;

    if (form1.introduce.value==""){
      alert("请输入商品简介!");form1.introduce.focus();return;

    form1.submit(); 
    }
    </script>
    <body>
    <table width="575"  border="0" align="center" cellpadding="-2" cellspacing="-2" bordercolordark="#FFFFFF">
      <form action="" method="post" name="form1">
        <tr>
          <td width="19%" height="27"> 商品名称:</td>
          <td height="27" colspan="3"> 
              <input name="goodsName" type="text" class="Sytle_text" id="bookID2" size="50">
       </td>
        </tr>
        <tr>
          <td height="27"> 所属大类:</td>
          <td width="25%" height="27"> 
              <select name="type" class="textarea" id="type" onChange="F_super(this.value)">
              <?php
              $link=mysql_connect("localhost","root","sa");
              mysql_select_db("db_database24",$link);
              $GB2312string=iconv( 'UTF-8', 'gb2312//IGNORE' , $RequestAjaxString);   //Ajax中先用encodeURIComponent对要提交的中文进行编码
              mysql_query("set names gb2312");
              $sql=mysql_query("select * from tb_type group by type");
              $result=mysql_fetch_object($sql);
              do{
              header('Content-type: text/html;charset=GB2312');  //指定发送数据的编码格式为GB2312
              ?>
               <option value="<?php echo $result->type;?>" selected><?php echo $result->type;?></option>
              <?php
              }while($result=mysql_fetch_object($sql));
              ?>
          </select></td>
          <td width="13%" height="27"> 所属小类:</td>
          <td width="43%" height="27" id="subType"> </td>
        </tr>
        <tr>
          <td height="41"> 图片文件:</td>
          <td height="41"> 
              <input name="picture" type="text" class="Style_upload" id="picture" size="20">
          </td>
          <td height="41"> 定  价:</td>
          <td height="41"> 
              <input name="price" type="text" class="Sytle_text" id="price" size="20">
            (元)</td>
        </tr>
        <tr>
          <td height="103"> 商品简介:</td>
          <td colspan="3"><span class="style5">  </span>
              <textarea name="introduce" cols="40" rows="5" class="textarea" id="introduce"></textarea></td>
        </tr>
        <tr>
          <td height="28" colspan="4" align="center"><input name="Button" type="button" class="btn_grey" value="保存" onClick="mycheck();">
     
            <input name="Submit2" type="reset" class="btn_grey" value="重置">
     </td>
        </tr>
      </form>
    </table>
    <script language="javascript">
    F_super(form1.type.value);
    </script>
    </body>
    </html>
    selSubType.php: 程序代码
    <?php
    $link=mysql_connect("localhost","root","sa");
    mysql_select_db("db_database24",$link);
    $GB2312string=iconv( 'UTF-8', 'gb2312//IGNORE',$RequestAjaxString);  //Ajax中先用encodeURIComponent对要提交的中文进行编码
    mysql_query("set names gb2312");
    $type=$_GET[type];
    $sql=mysql_query("select * from tb_type where type='$type'");
    $result=mysql_fetch_array($sql);
    header('Content-type: text/html;charset=GB2312');  //指定发送数据的编码格式为GB2312
    ?>
    <select name="typeID" class="textarea" id="typeID">
    <?php
    do{
    ?>
       <option value="<?php echo $result[subtype];?>"><?php echo $result[subtype];?></option>
    <?php
    }while($result=mysql_fetch_array($sql));
    ?> 
    </select>