Action:
CustomerinfosAction.class.php
<?php /* * 客户信息 控制器 * @author lifu <504861378@qq.com> * @time 2015/11/09 */ class CustomerinfosAction extends Action{ //获取登录用户录入的客户信息 public function getcustomerinfos(){ $Data = M(\'Customerinfos\'); $aid = $_SESSION[\'aid\']; import(\'ORG.Util.Page\');// 导入分页类 $count = $Data->where(array(\'aid\'=>$aid))->count();// 查询满足要求的总记录数 $lastpage = floor(($count/10)+1); $Page = new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数 $show = $Page->show();// 分页显示输出 // 进行分页数据查询 注意limit方法的参数要使用Page类的属性 $list = $Data->where(array(\'aid\'=>$aid))->limit($Page->firstRow.\',\'.$Page->listRows)->select(); $this->assign(\'list\',$list);// 赋值数据集 $this->assign(\'page\',$show);// 赋值分页输出 $this->assign(\'lastpage\',$lastpage); //echo $Data->getLastSql(); $this->search = $Data->where(array(\'aid\'=>$aid))->select(); $this->display(); echo "</div></div>"; } public function handlercustomername() { $customername = $_POST[\'wd\']; $Data = D(\'Customerinfos\'); $aid = $_SESSION[\'aid\']; $where[\'aid\']=$aid; //$where[\'customername\'] = array(\'like\',\'%\'.$customername.\'%\'); $where[\'customername\']=$customername; $result = $Data->where($where)->select(); //echo $Data->getLastSql(); echo json_encode($result,true); } public function handlerall() { $Data = D(\'Customerinfos\'); $aid = $_SESSION[\'aid\']; $result = $Data->field(\'customername\')->where(array(\'aid\'=>$aid))->select(); //echo $Data->getLastSql(); echo json_encode($result,true); } public function handlerlike() { $customername = $_POST[\'wd\']; $Data = D(\'Customerinfos\'); $aid = $_SESSION[\'aid\']; $where[\'aid\']=$aid; $where[\'customername\'] = array(\'like\',\'%\'.$customername.\'%\'); //$where[\'customername\']=$customername; $result = $Data->field(\'customername\')->where($where)->select(); //echo $Data->getLastSql(); echo json_encode($result,true); } public function handlerallphone() { $Data = D(\'Customerinfos\'); $aid = $_SESSION[\'aid\']; $result = $Data->field(\'customerphone\')->where(array(\'aid\'=>$aid))->select(); //echo $Data->getLastSql(); echo json_encode($result,true); } public function handlerlikephone() { $customerphone = $_POST[\'phone\']; $Data = D(\'Customerinfos\'); $aid = $_SESSION[\'aid\']; $where[\'aid\']=$aid; $where[\'customerphone\'] = array(\'like\',\'%\'.$customerphone.\'%\'); //$where[\'customername\']=$customername; $result = $Data->field(\'customerphone\')->where($where)->select(); //echo $Data->getLastSql(); echo json_encode($result,true); } public function handlerphone() { $customerphone = $_POST[\'phone\']; $Data = D(\'Customerinfos\'); $aid = $_SESSION[\'aid\']; $where[\'aid\']=$aid; //$where[\'customername\'] = array(\'like\',\'%\'.$customername.\'%\'); $where[\'customerphone\']=$customerphone; $result = $Data->where($where)->select(); //echo $Data->getLastSql(); echo json_encode($result,true); } public function handler() { $Data = D(\'Customerinfos\'); $result = $Data->select(); //echo $Data->getLastSql(); echo json_encode($result,true); } public function insert() { $Data = D(\'Customerinfos\'); $data[\'aid\']= $_SESSION[\'aid\']; $data[\'performanceperson\']=$_GET[\'performanceperson\']; $data[\'customername\']=$_GET[\'customername\']; $data[\'customerphone\']=$_GET[\'customerphone\']; $data[\'company\']=$_GET[\'company\']; $data[\'remarks\']=$_GET[\'remarks\']; $data[\'createtime\']=date("y-m-d H:i:s",time()); $result = $Data->add($data); if($result) { $this->success(\'操作成功\'); header("Location: /app/index.php/Customerinfos/getcustomerinfos/p/100"); } else { $this->error(\'操作失败\'); header("Location: /app/index.php/Customerinfos/getcustomerinfos/p/100"); } } public function editcustomer() { $Data = D(\'Customerinfos\'); $customerphone=$_GET[\'customerphone\']; $list =$Data->where(\'customerphone=\'.$customerphone)->find(); $this->list = $list;// 赋值数据 $this->display(); echo "</div></div>"; } public function updata() { $Data = D(\'Customerinfos\'); $data[\'id\']=$_GET[\'id\']; $data[\'aid\']=$_GET[\'aid\']; $data[\'performanceperson\']=$_GET[\'performanceperson\']; $data[\'customername\']=$_GET[\'customername\']; $data[\'customerphone\']=$_GET[\'customerphone\']; $data[\'company\']=$_GET[\'company\']; $data[\'remarks\']=$_GET[\'remarks\']; $data[\'createtime\']=$_GET[\'createtime\']; $result = $Data->save($data); //隐藏域有id if($result) { $this->success(\'success!\'); header("Location: /app/index.php/Customerinfos/getcustomerinfos/p/100"); }else{ $this->error(\'error!或未做任何修改!\'); header("Location: /app/index.php/Customerinfos/getcustomerinfos/p/100"); } } public function deletecustomer() { $Data = M(\'Customerinfos\'); $customerphone=$_POST[\'customerphone\']; $result = $Data->where(\'customerphone=\'.$customerphone)->delete(); if($result) { echo \'lost\'; }else{ echo \'success\'; } } }
Model:
CustomerinfosModel.class.php
<?php class CustomerinfosModel extends Model{ //指定数据库 protected $dbName = \'yloa\'; //定义模型字段 protected $fields = array( \'id\', \'aid\', \'performanceperson\', \'customername\', \'customerphone\', \'company\', \'remarks\', \'createtime\', \'_pk\' => \'id\', \'_autoinc\' => true ); // 定义自动验证 protected $_validate = array( array(\'aid\',\'require\',\'工号必须\'), array(\'performanceperson\',\'require\',\'业绩人必须\'), array(\'customername\',\'require\',\'客户姓名必须\'), array(\'customerphone\',\'require\',\'客户联系电话必须\'), array(\'company\',\'require\',\'公司名称必须\'), array(\'remarks\',\'require\',\'备注信息必须\'), array(\'createtime\',\'require\',\'创建时间必须\'), ); }
tp:
getcustomerinfos.html
<title>Get Cunstomerinfos</title> <include file="./Tpl/Home/index/index_layout.html"/> <link type="text/css" rel="stylesheet" href="/app/public/css/table.css" /> <script language="javascript" src="/app/public/js/cunstomerinfodroplist.js"></script> <div style="position:absolute;width:1425px;heigth:30px;top:30px;left:100px;"> <input type="button" id="add" value="添加" onclick="javascript:self.location=\'/app/index.php/Customerinfos/addcustomer\';" style="height:30px;width:75px" /> </div> <div style="position:absolute;width:1425px;heigth:30px;top:80px;left:100px;" > <form action=""> <div> 客户:<span id="searchname" style="cursor:pointer;"><input id="wd" type="text" onkeydown="KeyDown(event)" oninput="wdchange(event)" autocomplete="off" style="height:30px;width:110px" value="" /></span> <div id="show_wd" style="position:absolute;font-size:12px;border:blue 1px solid;top:35px;left:48px ;display:none; width:110px; background-color:#FFFFFF;"> <!--<table id=\'tb\'> <volist name="search" id="vo"> <tr onmouseover=\'hLight(this)\'><td onclick=\'completeField(this)\' style="cursor:pointer;">{$vo.customername}</td></tr> </volist> </table>--> </div> 电话:<span id="phonelist" style="cursor:pointer;"><input id="phone" type="text" onkeydown="KeyDown(event)" oninput="phonechange(event)" autocomplete="off" style="height:30px;width:110px" value="" /></span> <div id="show_phone" style="position:absolute;font-size:12px;border:blue 1px solid;top:35px;left:212px ;display:none; width:110px; background-color:#FFFFFF;"> </div> <input id="all" type="button" value="显示全部客户信息" style="height:30px;width:150px;display:none;" onClick="javascript:getall();" /> <?php if($_SESSION[\'grade\'] == 1 || $_SESSION[\'grade\'] == 2 ) echo "<script>$(\'#all\').show();</script>"; ?> </div> </form> <div id="result"> <table class=\'imagetable\'> <tr> <th>客户名字</th> <th>客户电话</th> <th>公司</th> <th>业绩人</th> <th>创建时间</th> <th>备注</th> <th>操作</th> </tr> <volist name="list" id="vo" key="k"> <tr align="center"> <td>{$vo.customername}</td> <td>{$vo.customerphone}</td> <td>{$vo.company}</td> <td>{$vo.performanceperson}</td> <td>{$vo.createtime}</td> <td>{$vo.remarks}</td> <td> <nobr><input type="button" id="edit" value="编辑" onclick="javascript:edit_customerphone({$vo.customerphone});" /><input type="button" id="delete" value="删除" onclick="javascript:delete_customerphone({$vo.customerphone});" /></nobr> </td> </tr> </volist> </table> <div style="position:absolute;width:1425px;heigth:30px;top:500px;" align="center"> <hr>{$page} <a href="/app/index.php/Customerinfos/getcustomerinfos/p/1">首页</a> <a href="/app/index.php/Customerinfos/getcustomerinfos/p/{$lastpage}">末页</a><hr> </div> </div> </div>
addcustomer.html
<title>Add Customer</title> <include file="./Tpl/Home/index/index_layout.html"/> <div style="position:absolute;width:1425px;heigth:30px;top:30px;left:100px;"> <form action="__URL__/insert"> <table border="0" cellspacing="1" > <caption align="top"><a style="color:#FFFFFF;" >新客户信息录入</a></caption> <tr> <th align="right"><a>业绩人:</a></th> <td><input type="text" name="performanceperson" /></td> <td align=\'left\' style=\'color:#FF0000\'>必须</td> </tr> <tr> <th align="right"><a>客户名字:</a></th> <td><input type="text" name="customername" /></td> <td align=\'left\' style=\'color:#FF0000\'>必须</td> </tr> <tr> <th align="right"><a>客户电话:</a></th> <td><input type="text" name="customerphone" /></td> <td align=\'left\' style=\'color:#FF0000\'>必须</td> </tr> <tr> <th align="right"><a>公司:</a></th> <td><input type="text" name="company" /></td> <td align=\'left\' style=\'color:#FF0000\'>必须</td> </tr> <tr> <th align="right"><a>备注:</a></th> <td><textarea name="remarks" style="background-color:#CDFF9A;height:285px;width:165px;resize:none;" onkeydown="checkMaxInput(this,120)" onkeyup="checkMaxInput(this,120)" onfocus="checkMaxInput(this,120)" onblur="checkMaxInput(this,120);resetMaxmsg()"></textarea></td> <td align=\'left\' style=\'color:#FF0000\'>必须</td> </tr> <tr> <td align=\'center\'><input type=\'reset\' value=\'重置\' /></td> <td align=\'right\'><input type=\'submit\' value=\'保存\' onclick=\'javascript:return confirm("请确认信息无误!");\' /></td> </tr> </table> <div style="position:absolute;top:200px;left:250px"><a style="display:none" id="number">剩(<span id="msg">120</span>)字</a></div> </form> <script type="text/javascript" src="/app/public/js/wordsnumber.js"></script>
editcustomer.html
<title>Edit Customer</title> <include file="./Tpl/Home/index/index_layout.html"/> <div style="position:absolute;width:1425px;heigth:30px;top:30px;left:100px;"> <form action="__URL__/updata"> <input type="hidden" name="id" value="{$list.id}" /> <input type="hidden" name="aid" value="{$list.aid}" /> <input type="hidden" name="createtime" value="{$list.createtime}" /> <table border="0" cellspacing="1"> <caption align="top"><a style="color:#FFFFFF;" >客户信息修改</a></caption> <tr> <th align="right"><a>业绩人:</a></th> <td><input type="text" name="performanceperson" value="{$list.performanceperson}" /></td> <td align=\'left\' style=\'color:#FF0000\'>必须</td> </tr> <tr> <th align="right"><a>客户名字:</a></th> <td><input type="text" name="customername" value="{$list.customername}" /></td> <td align=\'left\' style=\'color:#FF0000\'>必须</td> </tr> <tr> <th align="right"><a>客户电话:</a></th> <td><input type="text" name="customerphone" value="{$list.customerphone}" /></td> <td align=\'left\' style=\'color:#FF0000\'>必须</td> </tr> <tr> <th align="right"><a>公司:</a></th> <td><input type="text" name="company" value="{$list.company}" /></td> <td align=\'left\' style=\'color:#FF0000\'>必须</td> </tr> <tr> <th align="right"><a>备注:</a></th> <td><textarea name="remarks" style="background-color:#CDFF9A;height:285px;width:165px;resize:none;" onkeydown="checkMaxInput(this,120)" onkeyup="checkMaxInput(this,120)" onfocus="checkMaxInput(this,120)" onblur="checkMaxInput(this,120);resetMaxmsg()"></textarea></td> <td align=\'left\' style=\'color:#FF0000\'>必须</td> </tr> <tr> <td align=\'center\'><input type=\'reset\' value=\'重置\' /></td> <td align=\'right\'><input type=\'submit\' value=\'保存\' onclick=\'javascript:return confirm("请确认信息无误!");\' /></td> </tr> </table> <div style="position:absolute;top:200px;left:250px"><a style="display:none" id="number">剩(<span id="msg">250</span>)字</a></div> </form> <script type="text/javascript" src="/app/public/js/wordsnumber.js"></script>
CSS:
table.css
table.imagetable { font-family: verdana,arial,sans-serif; font-size:11px; color:#333333; border-width: 1px; border-color: #999999; border-collapse: collapse; } table.imagetable th { background:#b5cfd2 url(\'cell-blue.jpg\'); border-width: 1px; padding: 8px; border-style: solid; border-color: #999999; } table.imagetable td { background:#dcddc0 url(\'cell-grey.jpg\'); border-width: 1px; padding: 8px; border-style: solid; border-color: #999999; width:140px; height:30px; text-align:center; } .hlight{background-color:Red} .normal{backgroud-color:transparent;}
JS:
cunstomerinfodroplist.js 包括有 文本下拉框输入提醒 , 鼠标上下移动选择高亮, json 数据分页
$(function() { $(\'#wd\').focus(function(){ a=1; var ajaxurl = \'/app/index.php/Customerinfos/handlerall\'; var wd = $(\'#wd\').val(); if(wd == null || wd == undefined || wd == \'\' ) { $.post(ajaxurl,{},function(data){ $("#show_wd").html(setTablecustomername(data)).show(); },\'json\'); }else { var ajaxurl = \'/app/index.php/Customerinfos/handlerlike\'; $.post(ajaxurl,{\'wd\':wd},function(data){ $("#show_wd").html(setTablecustomername(data)).show(); },\'json\'); } }); $(\'#wd\').blur(function(){ setTimeout("lostshowwd()",1000); }); $(\'#phone\').blur(function(){ setTimeout("lostshowphone()",1000); }); $(\'#phone\').focus(function(){ a=2; var ajaxurl = \'/app/index.php/Customerinfos/handlerallphone\'; var phone = $(\'#phone\').val(); if(phone == null || phone == undefined || phone == \'\' ) { $.post(ajaxurl,{},function(data){ $("#show_phone").html(setTablephone(data)).show(); },\'json\'); }else { var ajaxurl = \'/app/index.php/Customerinfos/handlerlikephone\'; $.post(ajaxurl,{\'phone\':phone},function(data){ $("#show_phone").html(setTablephone(data)).show(); },\'json\'); } }); /* $(\'#wd\').change(function(){ var ajaxurl = \'/app/index.php/Customerinfos/handlerlike\'; var wd = $(\'#wd\').val(); $.post(ajaxurl,{\'wd\':wd},function(data){ $("#show_wd").html(setTable(data)).show(); },\'json\'); });*/ }) //隐藏div-show_wd function lostshowwd() { $("#show_wd").hide(); } //隐藏div-show_phone function lostshowphone() { $(\'#show_phone\').hide(); } function wdchange(event) { var ajaxurl = \'/app/index.php/Customerinfos/handlerlike\'; var wd = event.target.value; $.post(ajaxurl,{\'wd\':wd},function(data){ $("#show_wd").html(setTablecustomername(data)).show(); },\'json\'); } function phonechange(event) { var ajaxurl = \'/app/index.php/Customerinfos/handlerlikephone\'; var phone = event.target.value; $.post(ajaxurl,{\'phone\':phone},function(data){ $("#show_phone").html(setTablephone(data)).show(); },\'json\'); } //设置拼接setTablecustomername function setTablecustomername(json) { if(json == null || json == undefined || json == \'\') { $("#show_wd").html(\'\').hide(); return""; } var html ="<table id=\'tb\' width=\'100%\'>"; html+="<tr onmouseover=\'mousehover(this)\' onmouseout=\'mousemove(this)\' class=\'hlight\' ><td onclick=\'completeField(this)\'style=\'cursor:pointer;\'>"+json[0].customername+"</td></tr>"; for(var i=1;i<json.length;i++) { html+="<tr onmouseover=\'mousehover(this)\' onmouseout=\'mousemove(this)\'><td onclick=\'completeField(this)\' style=\'cursor:pointer;\'>"+json[i].customername+"</td></tr>"; } html +="</table>"; return html; } //设置拼接setTablephone function setTablephone(json) { if(json == null || json == undefined || json == \'\') { $("#show_phone").html(\'\').hide(); return "返回值为空!"; } var html = "<table id=\'tb\' width=\'100%\'>"; html+="<tr onmouseover=\'mousehover(this)\' onmouseout=\'mousemove(this)\' class=\'hlight\' ><td onclick=\'phoneField(this)\'style=\'cursor:pointer;\'>"+json[0].customerphone+"</td></tr>"; for(var i=1;i<json.length;i++) { html+="<tr onmouseover=\'mousehover(this)\' onmouseout=\'mousemove(this)\'><td onclick=\'phoneField(this)\' style=\'cursor:pointer;\'>"+json[i].customerphone+"</td></tr>"; } html +="</table>"; return html; } //选择一个选项客户名 function completeField(td) { document.getElementById(\'wd\').value=$(td).text(); $(\'#show_wd\').html(\'\').hide(); if(document.getElementById(\'wd\').value!=\'\') { var ajaxurl = \'/app/index.php/Customerinfos/handlercustomername\'; var wd = $(\'#wd\').val(); $.post(ajaxurl,{\'wd\':wd},function(data){ $(\'#result\').html(setcustomerinfo(data)); },\'json\'); } } //选择一个选项电话 function phoneField(td) { //alert($(td).text()); document.getElementById(\'phone\').value=$(td).text(); $(\'#show_phone\').html(\'\').hide(); if(document.getElementById(\'phone\').value!=\'\') { var ajaxurl = \'/app/index.php/Customerinfos/handlerphone\'; var phone = $(\'#phone\').val(); $.post(ajaxurl,{\'phone\':phone},function(data){ $(\'#result\').html(setcustomerinfo(data)); },\'json\'); } } //打印输出查询信息1 function setcustomerinfo(json) { if(json == null || json == undefined || json == \'\') { return "返回值为空!"; } var html = "<table class=\'imagetable\' id=\'tb\'>"; html+="<tr><th>客户名字</th><th>客户电话</th><th>公司</th><th>业绩人</th><th>创建时间</th><th>备注</th><th>操作</th></tr>"; for(i=0;i<json.length;i++){ html+="<tr align=\'center\'>"; html+="<td>"+json[i].customername+"</td><td>"+json[i].customerphone+"</td><td>"+json[i].company+"</td><td>"+json[i].performanceperson+"</td><td>"+json[i].createtime+"</td><td>"+json[i].remarks+"</td><td><nobr><input type=\'button\' id=\'edit\' value=\'编辑\' onclick=\'javascript:edit_customerphone("+json[i].customerphone+");\' /><input type=\'button\' id=\'delete\' value=\'删除\' onclick=\'javascript:delete_customerphone("+json[i].customerphone+");\' /></nobr></td>"; html+="</tr>"; } html+="</table>"; return html; } //移动上色 function mousehover(tr) { $(tr).addClass(\'hlight\'); } //移动去色 function mousemove(tr) { $(tr).removeClass(\'hlight\'); } //在输入框内点击上下回车 function KeyDown(evt) { evt = (evt) ? evt : ((window.event) ? window.event : "") //兼容IE和Firefox获得keyBoardEvent对象 var key = evt.keyCode?evt.keyCode:evt.which; //兼容IE和Firefox获得keyBoardEvent对象的键值 if(key==38) { //上 lightMove("up"); } if(key==40) { //下 lightMove("down"); } if(key==13) { //回车 lightMove("ok"); } } //高亮移动 function lightMove(cmd) { var tb = document.getElementById(\'tb\'); if(cmd=="up") { //上 for(var i=0;i<tb.rows.length;i++) { if(tb.rows[i].className=="hlight") { tb.rows[i].className="normal"; i=i==0?tb.rows.length-1:i-1; tb.rows[i].className="hlight"; } } } if(cmd=="down") { for(var i=0;i<tb.rows.length;i++) { if(tb.rows[i].className=="hlight") { tb.rows[i].className="normal"; i=i==tb.rows.length-1?0:i+1; tb.rows[i].className="hlight"; } } } if(cmd=="ok") { //alert(a); for(var i=0;i<tb.rows.length;i++) { if(tb.rows[i].className=="hlight") { if(a==1) { completeField(tb.rows[i]); } if(a==2) { phoneField(tb.rows[i]); } if(a==0) { alert("没有选择!"); } } } } } //--------------------------------------------------------------------------------- var a=0; //全局变量 var columns = [{"cid":"id","ctext":"序号"},{"cid":"aid","ctext":"工号"},{"cid":"performanceperson","ctext":"业绩人"},{"cid":"customername","ctext":"客户名字"},{"cid":"customerphone","ctext":"客户电话"},{"cid":"company","ctext":"公司"},{"cid":"remarks","ctext":"备注"},{"cid":"createtime","ctext":"创建时间"},{"cid":"edit","ctext":"操作"}]; var tableData=\'\'; //--------------------------------------------------------------------------------- //获得全部客户信息 function getall() { var ajaxurl = \'/app/index.php/Customerinfos/handler\'; $.post(ajaxurl,{},function(data){ $(\'#result\').html(setcustomerinfoallsplitPage(data)); tableData = JSON.stringify(data); //json转换为字符串 splitPage(1,10,tableData); },\'json\'); $("#wd").attr("disabled", \'true\'); $("#phone").attr("disabled", \'true\'); } //打印输出查询信息 function setcustomerinfoallsplitPage(json) { if(json == null || json == undefined || json == \'\') { return "返回值为空!"; } var html = "<table class=\'imagetable\' id=\'tb\'>"; html+="<tr><th>序号</th><th>工号</th><th>业绩人</th><th>客户名字</th><th>客户电话</th><th>公司</th><th>备注</th><th>创建时间</th><th>操作</th></tr>"; for(i=0;i<json.length;i++){ html+="<tr align=\'center\'>"; html+="<td>"+json[i].id+"</td><td>"+json[i].aid+"</td><td>"+json[i].performanceperson+"</td><td>"+json[i].customername+"</td><td>"+json[i].customerphone+"</td><td>"+json[i].company+"</td><td>"+json[i].remarks+"</td><td>"+json[i].createtime+"</td><td><nobr><input type=\'button\' id=\'edit\' value=\'编辑\' onclick=\'javascript:edit_customerphone("+json[i].customerphone+");\' /><input type=\'button\' id=\'delete\' value=\'删除\' onclick=\'javascript:delete_customerphone("+json[i].customerphone+");\' /></nobr></td>"; html+="</tr>"; } html+="</table><hr style=\'position:absolute;width:1425px;heigth:30px;top:480px;\'><div style=\'position:absolute;width:1425px;heigth:30px;top:500px;\' id=\'page_bar\' align=\'center\'></div><hr style=\'position:absolute;width:1425px;heigth:30px;top:520px;\'>"; return html; } //判断是否为json数据类型 function isjson(obj) { var isjson = typeof(obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && !obj.length; return isjson; } /** page:页码 pageSize:每页的记录条数 此方法除了传入page和pageSize之外,还应知道的有三个参数: 一、表的全部数据,json串格式,可通过action查询数据库得到。 二、表头所对应的列的key及名称,也是json串格式 三、表所对应的id 注:此处只是适合表头只有一行,且事先写好的情况。您可以根据需要改一下,逻辑思路就是这样,欢迎批评指正。 */ function splitPage(page,pageSize,json) { if(Object.prototype.toString.call(json) === "[object String]"){ //判断是否为字符串 var json=JSON.parse(json); //字符串转化为json } var ptable = document.getElementById("tb"); //获取表格对象 var num = ptable.rows.length;//table.rows返回表格中包含的所有行,此处假设表由表头1行和表体N行组成 //alert(num); //清除tbody for(var i=num-1;i>0;i--) { ptable.deleteRow(i); } var totalNums = json.length;//总行数 var totalPage = Math.ceil(totalNums/pageSize);//总页数 var begin = (page-1)*pageSize;//页起始位置(包括) var end = page*pageSize;//页结束位置(不包括) end = end>totalNums?totalNums:end; //向tbody中写入数据 var n = 1;//tbody的起始行 for(var i=begin;i<end;i++) { var row = ptable.insertRow(n++); var rowData = json[i]; for(var j=0;j<columns.length;j++) { var col = columns[j].cid; var cell = row.insertCell(j); var cellData = rowData[col]; cell.innerHTML = cellData; } } //生成分页工具条 var pageBar = "第"+page+"页/共"+totalPage+"页"+" "; if(page>1) { pageBar += "<a href=\'javascript:splitPage("+1+","+pageSize+","+tableData+");\'>首页</a> "; } else { pageBar += "首页 "; } if(page>1) { pageBar += "<a href=\'javascript:splitPage("+(page-1)+","+pageSize+","+tableData+");\'>上一页</a> "; } else { pageBar += "上一页 "; } if(page<totalPage) { pageBar += "<a href=\'javascript:splitPage("+(page+1)+","+pageSize+","+tableData+");\'>下一页</a> "; } else { pageBar += "下一页 "; } if(page<totalPage) { pageBar += "<a href=\'javascript:splitPage("+(totalPage)+","+pageSize+","+tableData+");\'>尾页</a> "; } else { pageBar += "尾页 "; } $(\'#page_bar\').html(pageBar).show(); } //编辑cunstomerinfos function edit_customerphone(mycustomerphone) { var Url="/app/index.php/Customerinfos/editcustomer/customerphone/"; window.location.href=(Url+mycustomerphone); } //删除cunstomerinfos function delete_customerphone(mycustomerphone) { confirm(\'确认删除吗?\'); var ajaxUrl = "/app/index.php/Customerinfos/deletecustomer"; var customerphone= mycustomerphone; $.post(ajaxUrl,{"customerphone":customerphone},function(data){ if(data==\'lost\') { alert(\'删除成功\'); window.location.reload(); } else if(data==\'success\') { alert(\'删除失败\'); window.location.reload(); } }); }
wordsnumber.js 计算控制字数
//多行文本输入框剩余字数计算 function checkMaxInput(obj, maxLen) { if (obj == null || obj == undefined || obj == "") { return; } /* if (maxLen == null || maxLen == undefined || maxLen == "") { maxLen = 250; }*/ /* var strResult; var $obj = $(obj); var newid = $obj.attr("id") + \'msg\';*/ $(\'#number\').show(); if (obj.value.length > maxLen) { //如果输入的字数超过了限制 obj.value = obj.value.substring(0, maxLen); //就去掉多余的字 document.getElementById("msg").innerHTML ="剩"+(maxLen - obj.value.length).toString()+"字"; //strResult = \'<a><span id="\' + newid + \'" class=\\'Max_msg\\' ><br/>剩(\' + (maxLen - obj.value.length) + \')字</span></a>\'; //计算并显示剩余字数 } else { //strResult = \'<a><span id="\' + newid + \'" class=\\'Max_msg\\' ><br/>剩(\' + (maxLen - obj.value.length) + \')字</span></a>\'; //计算并显示剩余字数 document.getElementById("msg").innerHTML =(maxLen - obj.value.length).toString(); } /* var $msg = $("#" + newid); if ($msg.length == 0) { $obj.after(strResult); } else { $msg.html(strResult); }*/ } //清空剩除字数提醒信息 function resetMaxmsg() { $(\'#number\').hide(); }
效果: