My Code Snippet

 加载菜单(js)

function mkmenu(menus,name,id,parentid,url)

{

    $.each(menus,function(i){

        menus[i].children=new Array();

        menus[i].parent=-1;

    });

    $.each(menus,function(i){

        var pid=menus[i][parentid];

        $.each(menus,function(j){

            if(menus[j][id]==pid)

            {

                menus[j].children.push(i);

                menus[i].parent=j;

                return;

            }

        });

    });





    var root={};

    root.node=$('<div></div>');

    root.children=new Array();





    $.each(menus,function(i){

        if(menus[i].parent==-1){root.children.push(i);}

        var tmp=$('<li></li>');

        if(menus[i][url]=='')tmp.html(menus[i][name]);

        else{

            $("<a></a>").attr('href',menus[i][url]).appendTo(tmp).html(menus[i][name]);

        }

        menus[i].node=tmp;

        

    });

    function addchildren(parent)

    {

        $("<ul></ul>").appendTo(parent.node);

        $.each(parent.children,function(i){



            if(menus[parent.children[i]].children.length>0)addchildren(menus[parent.children[i]]);

            menus[parent.children[i]].node.appendTo(parent.node.children('ul'));

        });

    }

    addchildren(root);

    root.node.appendTo('body');

}

显示分页(js)

function pagination(total,curpage)

{

    if(total<0)return "";

    if(curpage<0 || curpage>total)return "";

    var atag=$('<a></a>');

    var spantag=$('<span></span>');

    var left="";

    var right="";

    if(curpage>7)

    {

        left="<a href='?p="+(curpage-1).toString()+"'><span></span></a><a href='?p=1'><span>1</span></a>...";

        for(var i=0;i<5;i++)

        {

            left+="<a href='?p="+(curpage-5+i).toString()+"'><span>"+(curpage-5+i).toString()+"</span></a>";

        }

    }

    else

    {

        

        if(curpage==1)

        {

            left="<a href='#'><span></span></a>";

        }

        else

        {    

            left="<a href='?p="+(curpage-1).toString()+"'><span></span></a>";

            for(var i=0;i<curpage-1;i++)

            {

                left+="<a href='?p="+(i+1).toString()+"'><span>"+(i+1).toString()+"</span></a>";

            }

        }

    }



    if(curpage>(total-7))

    {

        if(curpage==total)

        {

            right="<a href='#'><span></span></a>";

        }

        else

        {

            for(var i=curpage+1;i<total+1;i++)

            {

                right+="<a href='?p="+i.toString()+"'><span>"+(i).toString()+"</span></a>";

            }

            right+="<a href='?p="+(curpage+1).toString()+"'><span></span></a>";

        }

    }

    else

    {

        for(var i=curpage+1;i<curpage+6;i++)

        {

            right+="<a href='?p="+i.toString()+"'><span>"+(i).toString()+"</span></a>";

        }

        right+="...<a href='?p="+total.toString()+"'><span>"+total.toString()+"</span></a><a href='?p="+(curpage+1).toString()+"'><span></span></a>"

    }



    return left+"<a href='?p="+curpage.toString()+"'><span class='curpage'>"+curpage.toString()+"</span></a>"+right;

}

生成表格(PHP)

function mktable($array,$alias,$rows,$pk,$operations=['edit'=>'编辑','del' => '删除'],$url_prefix="",$op=true,$filter=true,$chkbox=true,$bottom=true)

{



   echo "<table>";

   if($filter)

   {

    echo "<tr class='tbmng'>";

    echo "<td colspan='0'>通用操作</td>";

    echo "</tr>";

    echo "<tr>";

    echo "<td colspan='0' id='tbmng'></td>";

    echo "</tr>";

   }

   

   echo "<tr class='tbhead'>";

   if($chkbox)echo "<td><input type='checkbox' value='1'></td>";

   foreach ($alias as $key => $value) {

        echo "<td>".$value."</td>";

   }



   if($op)echo "<td>".'操作'."</td>";

   echo "</tr>";

   for($i=0;$i<count($array);$i++)

   {

        echo "<tr>";

        if($chkbox)echo "<td><input type='checkbox' value='1'></td>";

        foreach ($alias as $key => $value) {

            echo "<td>".$array[$i][$key]."</td>";

        }

        if($op)

        {

            echo "<td>";

            foreach($operations as $key=>$value)

            {

                echo "<a href='".$url_prefix.$key.'/'.$array[$i][$pk]."'>".$value;

                echo "</a>";

            }

            echo "</td>";

        }

        echo "</tr>";

   }

   

   echo "</table>";

   echo "<div>共<span></span>条记录,显示第<span></span>/<span></span>页</div>";



}

 

你可能感兴趣的:(code)