php中无极分类—>新闻列添加。

it2026-05-07  6

<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);                    }?>

转载于:https://www.cnblogs.com/mnboss/p/4206060.html

相关资源:数据结构—成绩单生成器
最新回复(0)