php中無極分類—>新聞列添加。

來源:互聯網
上載者:User

標籤:

<form action="" method="post" >
            <fieldset>
            <p>
              <label>標題</label>
              <input class="text-input small-input" type="text" id="small-input" name="name" />
             <!-- <input class="text-input small-input" id="small-input" name="title" />-->
             
              <!--名字儘可能與資料表的欄位名一致-->
              <span class="input-notification success png_bg">Successful message</span>
              <br />
              <small>A small description of the field</small> </p>
            
             <p>
              <label>父ID</label>
              <input class="text-input small-input" type="text" id="pid" name="pid" readonly="readonly" />
              </p>
              <p id="Pid">
              <select class="text-input small-input" id="pid0">
              <option value="0" status="0">頂級</option>
              <?php foreach($result as $value){ ?>
              <option value="<?php echo $value[‘id‘] ?>" status="1"><?php echo $value[‘name‘] ?></option>
              <?php } ?>
              </select>
            </p>
            <p>
              <input class="button" type="submit" value="Submit" />
            </p>
            </fieldset>
            <div class="clear"></div>
            <!-- End .clear -->
          </form>

 

//ajax交換。

$(function(){
         $(‘#Pid select‘).live(‘change‘,function(){
            //首先要擷取id
            var id=$(this).attr(‘value‘)
            //擷取層級。
            var level=$(this).attr(‘id‘).substr(3)
            $(‘#pid‘).attr(‘value‘,id)
            var status=$(this).find(‘option:select‘).attr(‘status‘);
            $.ajax({
                type:"GET",
                url:"index.php?c=category&a=next&admin=1&id="+id,
                 dataType:"json",
                 success: function(json){
                     var next_level=Number(level)+1
                     var tmp_level=next_level
                     while($(‘#pid‘+tmp_level).length !=0){
                         $(‘#pid‘+tmp_level).remove();
                         tmp_level++
                     }
                     if(json.length !=0&&status==1){
                         var l=‘‘
                            l+=‘ <select class="text-input small-input" id="pid‘+next_level+‘">‘
                        for(var i=0;i<json.length;i++){
                            l+=‘<option value="‘+json[i].id+‘" status="1">‘+json[i].name+‘</option>‘
                        }
                        l+=‘</select>‘
                        $(‘#Pid‘).append(l)
                     }
                 }
            })
            return false
         })
        
        
        
         })
 
 
 
  </script>

//函數的封裝

function getList($perpage,$offset,$table,$con=‘1‘){
 
  $sql="select * from $table where $con order by id desc limit $offset,$perpage";
          $query=mysql_query($sql);
          $result=array();
      while($row=mysql_fetch_assoc($query)){
            
          $result[]=$row;
        }    
        return $result;
    }

//php後台控制器

<?php
    $id=!empty($_GET[‘id‘])?$_GET[‘id‘]:0;
      $arr=getList(100,0,‘category‘,‘pid=‘.$id);//函數調用
        if(!empty($_SERVER[‘HTTP_X_REQUESTED_WITH‘])){//$_SERVER是系統內容變數,已經定義好的。
            echo json_encode($arr);
            
        }
?>

php中無極分類—>新聞列添加。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.