Js制作简单的网页

╰+哭是因爲堅強的太久メ 2022-06-10 13:38 313阅读 0赞



一个简易的纯JS的CRM管理系统

1 概述

  1. 这是一个综合的JS开发的管理系统,仅有基本功能,大约1500行代码,使用本地的数据localStorage作为临时测试数据的存储,同时用到了sessionStorage作为用户登陆信息的存储。该管理系统从用户登陆、注册到退出都采用了相关联的操作,让用户在没有登陆的情况下无法进入主页,有3天记住密码的选项,而且搜索中用了很多oninput事件更加人姓化,而且还有分页、修改密码、模糊查询等。

2 效果图如下:

Center

Center 1

Center 2

3 主要功能

  1. 管理系统从用户登陆、注册到退出都采用了相关联的操作,让用户在没有登陆的情况下无法进入主页,有3天记住密码的选项,而且搜索中用了很多oninput事件更加人姓化,而且还有分页、修改密码、模糊查询等。

4实现方式

首先 ,就是常规的网页布局,需要一定的基础来做界面。

  1. 登陆界面如下:

<div class=”content”>
<div class=”cont”>
<div class=”left”>
<div class=”logo”>
<span class=”title”>小微</span><br/>
<span class=”describe”>全球最专业的CRM</span>
</div>
</div>
<div class=”right”>
<div class=”rightCell”>
<div class=”login”>
<ul>
<li><sapn class=”loginTiTle”>用户登陆</sapn><span>user login</span></li>
<li class=”inputLi”><div class=”userName_logo”></div><input id=”userName” class=”input” type=”text” οninput=”getPassword(this)”/></li>
<li class=”inputLi”><div class=”passWord_logo”></div><input id=”passWord” class=”input” type=”password”/></li>
<br/><br/>
<li><input type=”checkbox” class=”withoutP” /><span> 3天内记住密码</span></li>
<li><input type=”button” class=”btnLi” value=”登录” οnclick=”*login()/></li>
<li><input type=”button” class=”btnLi” value=”注册” οnclick=”
goRegister()/></li>
</ul>
</div>
</div>
</div>
</*div
>

  1. <**div class="footer"**>
  2. </**div**>

</div>
</body>

  1. Css如下:
  2. *{
  3. margin: 0;
  4. padding: 0;
  5. }
  6. .content{
  7. width: 100%;
  8. height: 100%;
  9. position: absolute;
  10. background-color: gray;
  11. }
  12. .cont{
  13. width: 100%;
  14. height: 80%;
  15. background: url("img/index_bg.jpg");
  16. background-size:cover ;
  17. background-repeat: no-repeat;
  18. position: relative;
  19. }
  20. .cont .logo{
  21. width: 300px;
  22. height: 200px;
  23. position: absolute;
  24. left:50%;
  25. top: 15%;
  26. }
  27. .cont .logo span{
  28. display: block;
  29. color:white;
  30. font-family: 楷体;
  31. text-align: center;
  32. }
  33. .cont .logo .title{
  34. font-size:80px;
  35. }
  36. .cont .logo .describe{
  37. font-size: 40px;
  38. }
  39. .cont .left{
  40. width: 50%;
  41. height: 100%;
  42. position: absolute;
  43. }
  44. .cont .right{
  45. width: 50%;
  46. height: 100%;
  47. position: absolute;
  48. right: 0;
  49. }
  50. .cont .rightCell{
  51. width: 300px;
  52. height: 400px;
  53. position: absolute;
  54. left: 30%;
  55. top: 10%;
  56. }
  57. .cont .right ul{
  58. list-style: none;
  59. }
  60. .cont .right span{
  61. color: #030404;
  62. font-size: 18px;
  63. }
  64. .cont .right .loginTiTle{
  65. font-weight: bolder;
  66. font-size: 30px;
  67. line-height: 60px;
  68. }
  69. .cont .right ul li {
  70. margin-top: 15px;
  71. }
  72. .cont .right .input{
  73. border: 0;
  74. background-color: transparent;
  75. outline: none;
  76. line-height: 25px;
  77. }
  78. .cont .right .inputLi{
  79. line-height: 45px;
  80. background-color: #fff3cd;
  81. border-radius: 5px;
  82. }
  83. .cont .right .btnLi{
  84. width: 100%;
  85. line-height: 45px;
  86. background-color: #1a1402;
  87. border-radius: 8px;
  88. color: #efaf06;
  89. font-size: 20px;
  90. font-weight: bolder;
  91. letter-spacing: 10px;
  92. text-align: center;
  93. }
  94. .cont .right .login div{
  95. display: inline-block;
  96. width: 30px;
  97. height: 30px;
  98. vertical-align: middle;
  99. background-position: -3px -5px;
  100. }
  101. .cont .right .login .userName_logo{
  102. background-image: url("img/account_bg.png");
  103. }
  104. .cont .right .login .passWord_logo{
  105. background-image: url("img/passw_bg.png");
  106. }
  107. .footer{
  108. width: 100%;
  109. height: 20%;
  110. background-color: white;
  111. overflow: hidden;
  112. position: relative;
  113. }
  114. .footer p{
  115. margin: 4% 10%;
  116. }
  117. .footer .right{
  118. position: absolute;
  119. right: 2%;
  120. top: 30%;
  121. }
  122. footer .right img{
  123. vertical-align: middle;
  124. }
  1. 主页如下:







    客户关系管理平台
    1. <img src="img/photo.jpg" alt="图片加载失败!" width="70%" class="uimg"/>
    2. <div class="us"></div>
    3. </div>
    4. </div>
    5. <div class="right">
    6. <div class="top">
    7. <div class="lie" onclick="getPage(1)">客户管理</div>
    8. <div class="lie" onclick="getPage(2)">拜访记录</div>
    9. <div class="lie" onclick="getPage(3)">客户订单</div>
  1. <img src="img/quit.png" alt="" onclick="quit()"/>
  2. <img src="img/password.png" alt="" onclick="changeSate('changePassword')"/>
  3. </div>
  4. <div class="toolbar"></div>
  5. <div class="tableBar">
  6. <div class="lieTable" id="customer">
  7. <span onclick="changePage(this)">客户管理 </span>
  8. <div class="exit" onclick="exit(this)"></div>
  9. </div>
  10. <div class="lieTable" id="record" style="display: none">
  11. <span onclick="changePage(this)">拜访记录</span>
  12. <div class="exit" onclick="exit(this)"></div>
  13. </div>
  14. <div class="lieTable" id="order" style="display: none">
  15. <span onclick="changePage(this)">客户订单</span>
  16. <div class="exit" onclick="exit(this)"></div>
  17. </div>
  18. </div>
  19. <div class="content">
  20. <iframe class="page" src="homePage_1.html" frameborder="0"></iframe>
  21. <!--<img src="img/none-box.png" alt="图片加载失败!"/>-->
  22. </div>
  23. </div>
  24. <div class="changePassword" id="changePassword" style="display:none;" >
  25. <div class="top" id="changePasswordTop">
  26. <div class="close" onclick="changeSate('changePassword')"></div>
  27. </div>
  28. <div class="cont">
  29. <form action="">
  30. <table width="80%">
  31. <tr>
  32. <td><span>原密码</span></td>
  33. <td><input type="text" id="oPw"/></td>
  34. </tr>
  35. <tr>
  36. <td><span>新密码</span></td>
  37. <td><input type="text" id="nPw"/></td>
  38. </tr>
  39. <tr>
  40. <td><span>确认密码</span></td>
  41. <td><input type="text" id="qPw"/></td>
  42. </tr>
  43. <tr>
  44. <td><input class="set" type="reset"/></td>
  45. <td><input class="set" type="reset" value="确定" onclick="changeThePassWord()"/></td>
  46. </tr>
  47. </table>
  48. </form>
  49. </div>
  50. </div>
  51. </div>
  52. Css如下:

<style>
*{
margin: 0;
padding: 0;
}
html{
height: 100%;
}
body{
height: 100%;
}
.container{
width: 100%;
height: 100%;
}
.left{
width: 20%;
height: 100%;
background-color: #202a2d;
float: left;
}
.left .t{
margin: 20%;
}
.left .t div{
color: #fda408;
text-align: center;
}
.left .t .uimg{
margin: 15%;
border: 2px solid white;
border-radius:100%;
}
.left .t .us{
color: white;
}

  1. .**right**\{
  2. **width**: 80%;
  3. **height**: 100%;
  4. **float**: **right**;
  5. **overflow**: **hidden**;
  6. \}
  7. .**right** .**top**\{
  8. **width**: 100%;
  9. **height**: 6%;
  10. **background-color**: **\#334149**;
  11. **float**: **left**;
  12. **overflow**: **hidden**;
  13. \}
  14. .**right** .**top** .**lie**\{
  15. **height**: 100%;
  16. **width**:15%;
  17. **margin-right**:5%;
  18. **line-height**: 350%;
  19. **text-align**: **center**;
  20. **cursor**: **pointer**;
  21. **color**: **white**;
  22. **float**: **left**;
  23. \}
  24. .**right** .**top** .**lie**:**hover**\{
  25. **background-color**: **orange**;
  26. **font-size**: 18**px**;
  27. **line-height**: 50**px**;
  28. **transition**: **all** 0.2**s** ;
  29. \}
  30. .**right** .**top img**\{
  31. **width**: 2%;
  32. **margin**: 15**px**;
  33. **float**: **right**;
  34. **cursor**: **pointer**;
  35. \}
  36. .**right** .**top img**:**hover**\{
  37. **opacity**: 0.8;
  38. \}
  39. .**right** .**toolbar**\{
  40. **width**: 100%;
  41. **height**: 6%;
  42. **background-color**: **\#f5b702**;
  43. **float**: **left**;
  44. **overflow**: **hidden**;
  45. \}
  46. .**right** .**tableBar**\{
  47. **width**: 100%;
  48. **height**: 6%;
  49. **background-color**: **\#3d3d3d**;
  50. **float**: **left**;
  51. **overflow**: **hidden**;
  52. **position**: **relative**;
  53. \}
  54. .**right** .**tableBar div**\{
  55. **height**: 75%;
  56. **width**:8%;
  57. **margin-left**:2%;
  58. **margin-right**:2%;
  59. **margin-top**: 1.3%;
  60. **line-height**: 220%;
  61. **text-align**: **center**;
  62. **cursor**: **pointer**;
  63. **color**: **white**;
  64. **border**: 2**px solid black**;
  65. **background-color**: **rgba**(61, 61, 61, 0.8);
  66. **box-shadow**: 10**px** 10**px** 10**px black**;
  67. **border-radius**: 8**px**;
  68. **float**: **left**;
  69. **transition**: **all** 0.15**s**;
  70. **position**: **relative**;
  71. \}
  72. .**right** .**tableBar** .**lieTablespan**\{
  73. **display**: **inline-block**;
  74. \}
  75. .**right** .**tableBar** .**exit**\{
  76. **height**: 100%;
  77. **width**: 10%;
  78. **position**: **absolute**;
  79. **right**: 0;
  80. **top**: 0;
  81. **background-color**: **red**;
  82. \}
  83. .**right** .**tableBar div**:**hover**\{
  84. **opacity**: 0.5;
  85. \}
  86. .**right** .**content**\{
  87. **width**:100%;
  88. **height**: 82%;
  89. \}
  90. .**right** .**content img**\{
  91. **position**: **absolute**;
  92. **left**: 50%;
  93. **top**: 50%;
  94. **background-repeat**: **no-repeat**;
  95. \}
  96. .**container**:**after**\{
  97. **content**: **""**;
  98. **display**: **block**;
  99. **clear**: **both**;
  100. \}
  101. .**content** .**page**\{
  102. **width**: 100%;
  103. **height**: 100%;
  104. \}
  105. **\#customer**\{
  106. **background-color**: **\#b3b3b3**;
  107. \}
  108. .**changePassword**\{
  109. **width**: 400**px**;
  110. **height**: 450**px**;
  111. **font-weight**: **bolder**;
  112. **position**: **absolute**;
  113. **border-radius**: 10**px**;
  114. **left**: 36%;
  115. **top**: 110**px**;
  116. **border**: 2**px solid black**;
  117. **overflow**: **hidden**;
  118. \}
  119. .**changePassword** .**top**\{
  120. **width**: 100%;
  121. **height**: 8%;
  122. **background-color**: **\#464646**;
  123. **border-radius**: 8**px**;
  124. **position**: **relative**;
  125. \}
  126. .**changePassword** .**top** .**close**\{
  127. **height**: 60%;
  128. **width**: 5%;
  129. **background**: **url**(**"img/cha.png"**);
  130. **background-size**: **cover**;
  131. **position**: **absolute**;
  132. **right**: 2%;
  133. **top**: 20%;
  134. **cursor**: **pointer**;
  135. \}
  136. .**changePassword** .**cont**\{
  137. **width**: 100%;
  138. **height**: 92%;
  139. **border-radius**: 8**px**;
  140. **background**:**url**(**"img/adBg.png"**);
  141. **background-repeat**: **no-repeat**;
  142. **background-size**: **cover**;
  143. **opacity**: 0.95;
  144. **overflow**: **hidden**;
  145. \}
  146. .**changePassword** .**conttable**\{
  147. **margin**: 80**px auto**;
  148. **text-align**: **center**;
  149. \}
  150. .**changePassword** .**conttable tr**\{
  151. **height**: 35**px**;
  152. **line-height**: 50**px**;
  153. \}
  154. .**changePassword** .**conttable input**\{
  155. **width**: 150**px**;
  156. **height**: 28**px**;
  157. **border-radius**: 5**px**;
  158. **text-align**: **center**;
  159. \}
  160. .**changePassword** .**conttable** .**set**\{
  161. **width**: 76%;
  162. **height**:40**px**;
  163. **background-color**: **\#1a1402**;
  164. **border-radius**: 5**px**;
  165. **color**: **white**;
  166. **font-size**: 16**px**;
  167. **font-weight**: **bolder**;
  168. **letter-spacing**: 5**px**;
  169. **text-align**: **center**;
  170. **margin-top**: 60**px**;
  171. \}
  1. 注册界面如下:

    1. <h1>请填写以下信息!</h1>
    2. <table class="register">
    3. <tr>
    4. <td>用户名:</td>
    5. <td><input type="text" id="userName" class="input" /></td>
    6. </tr>
  1. <tr>
  2. <td>密码:</td>
  3. <td><input type="password" id="passWord" class="input" /></td>
  4. </tr>
  5. <tr>
  6. <td>确认密码:</td>
  7. <td><input type="password" id="passWord2" class="input" /></td>
  8. </tr>
  9. </table>
  10. <input type="button" class="btnLi" value="注册" onclick="register()"/>
  11. </div>
  12. Css如下:
  13. <style>
  14. *{
  15. margin: 0;
  16. padding: 0;
  17. }
  18. .container {
  19. width: 100%;
  20. height: 80%;
  21. background: orange;
  22. text-align: center;
  23. position: absolute;
  24. }
  25. .btnLi{
  26. width: 240px;
  27. line-height: 45px;
  28. background-color: #1a1402;
  29. border-radius: 5px;
  30. color: #efaf06;
  31. font-size: 20px;
  32. font-weight: bolder;
  33. letter-spacing: 10px;
  34. text-align: center;
  35. margin: 50px;
  36. }
  37. .container h1{
  38. color: white;
  39. font-family: 楷体;
  40. margin: 50px auto;
  41. }
  42. .container table tr{
  43. line-height: 50px;
  44. }
  45. .input{
  46. width:150px;
  47. height:25px;
  48. border-radius: 5px;
  49. }
  50. .register {
  51. margin:0 auto;
  52. }
  53. </style>

五、添加各种js来实现网页的数据交互

  1. ①、登陆界面的主要js方法:
  2. 我们更具一定的条件,需要初始化数据,然后实现界面的跳转以及登陆的简单判断
  3. var userArray=[];
  4. window.onload=function(){
  5. initUser();
  6. //从本地取得用户的用户名和密码,并转换成对象数组
  7. var userArrayStr=localStorage.userInfo||"";
  8. userArray=eval("("+userArrayStr+")");
  9. };
  10. function initUser(){
  11. if(!localStorage.userInfo) {
  12. var uArray = [{
  13. userName: "zhangsan",
  14. passWord: "123"
  15. }];
  16. var str = JSON.stringify(uArray);
  17. localStorage.userInfo = str;
  18. }
  19. if(!localStorage.customerInfo) {
  20. var customerArray=[{
  21. cNo:"1",
  22. cName:"张三",
  23. cCity:"山东烟台",
  24. cAddr:"创业科技大厦",
  25. cManager:"李四",
  26. cPost:"212121",
  27. cPhone:"15155152632",
  28. cStars:"3"
  29. },{
  30. cNo:"2",
  31. cName:"asd",
  32. cCity:"ads",
  33. cAddr:"666",
  34. cManager:"66",
  35. cPost:"567",
  36. cPhone:"asd",
  37. cStars:"1"
  38. }];
  39. //增加大数据
  40. for(var i=3;i<50;i++){
  41. var obj={
  42. cNo:i,
  43. cName:"张三",
  44. cCity:"山东烟台",
  45. cAddr:"创业科技大厦",
  46. cManager:"李四",
  47. cPost:"212121",
  48. cPhone:"15155152632",
  49. cStars:"3"
  50. };
  51. customerArray.push(obj);
  52. }
  53. var str=JSON.stringify(customerArray);
  54. localStorage.customerInfo=str;
  55. }
  56. // localStorage.clear();
  57. }
  58. function getPassword(cell){
  59. for(var i=0;i<userArray.length;i++){
  60. if((cell.value==userArray[i].userName)&&userArray[i].withoutP){
  61. if(new Date().getTime()<userArray[i].withoutP){
  62. document.getElementById("passWord").value=userArray[i].passWord;
  63. break;
  64. }
  65. }else{
  66. document.getElementById("passWord").value="";
  67. }
  68. }
  69. }
  70. function login(){
  71. var userName=document.getElementById("userName").value;
  72. var passWord=document.getElementById("passWord").value;
  73. var withoutP=document.getElementsByClassName("withoutP")[0];
  74. var isLogin=false;
  75. for(var i=0;i<userArray.length;i++){
  76. if((userName==userArray[i].userName)&&(passWord==userArray[i].passWord)){
  77. isLogin=true;
  78. sessionStorage.userName=userName;
  79. location.assign("homePage.html");
  80. if(withoutP.checked){
  81. userArray[i].withoutP=new Date().getTime()+259200000;
  82. var str=JSON.stringify(userArray);
  83. localStorage.userInfo=str;
  84. }
  85. }
  86. }
  87. if(!isLogin){
  88. alert("用户名或密码错误!");
  89. }
  90. }
  91. function goRegister(){
  92. location.assign("register.html");
  93. }

②、主页的主要方法:

  1. 这里的弹窗是用div模拟出来的,通过控制divdisplay来是实现弹窗的显示和消失、同时也可以拖拽,增加监听事件,同时增加分页效果,来实现大量数据显示时的人性化
  2. <script>
  3. var myX=0;
  4. var myY=0;
  5. var go=false;
  6. var changePassword;
  7. var offsetx=0;
  8. var offsety=0;
  9. document.onmousemove=function(e){
  10. var cont=document.getElementById("container");
  11. myX= e.clientX;
  12. myY= e.clientY;
  13. if(go){
  14. changePassword.style.left=myX-offsetx+"px";
  15. changePassword.style.top=myY-offsety+"px";
  16. //限定位置
  17. if(parseFloat(changePassword.style.left)<0)changePassword.style.left=0+"px";
  18. if(parseFloat(changePassword.style.top)<0)changePassword.style.top=0+"px";
  19. if(parseFloat(parseFloat(changePassword.style.left)+changePassword.offsetWidth)>cont.offsetWidth){
  20. changePassword.style.left=cont.offsetWidth-changePassword.offsetWidth+"px";
  21. }
  22. if(parseFloat(parseFloat(changePassword.style.top)+changePassword.offsetHeight)>cont.offsetHeight-30){
  23. changePassword.style.top=cont.offsetHeight-changePassword.offsetHeight-30+"px";
  24. }
  25. }
  26. };
  27. document.onmouseup=function(){
  28. go=false;
  29. };
  30. window.onload=function(){
  31. initUserInfo();
  32. changePassword=document.getElementById("changePassword");
  33. var changePasswordTop=document.getElementById("changePasswordTop");
  34. //鼠标按下
  35. changePassword.onmousedown=function(e){
  36. if(e.target==changePasswordTop){
  37. go=true;
  38. offsetx= e.offsetX;
  39. offsety= e.offsetY;
  40. }
  41. };
  42. //失去焦点
  43. changePassword.onblur=function(){
  44. go=false;
  45. };
  46. if(!sessionStorage.userName){
  47. location.assign("login.html");
  48. }
  49. };
  50. function initUserInfo(){
  51. var user=document.getElementsByClassName("us")[0];
  52. str="用户:";
  53. str+=sessionStorage.userName||"";
  54. user.innerHTML=str;
  55. }
  56. function getPage(index){
  57. var page=document.getElementsByClassName("page")[0];
  58. var lieTables=document.getElementsByClassName("lieTable");
  59. clear();
  60. lieTables[0].src="homePage_1.html";
  61. lieTables[1].src="homePage_2.html";
  62. lieTables[2].src="homePage_3.html";
  63. var src;
  64. switch (index){
  65. case 1:
  66. src="homePage_1.html";
  67. lieTables[0].style.display="block";
  68. lieTables[0].style.backgroundColor="#b3b3b3";
  69. break;
  70. case 2:
  71. src="homePage_2.html";
  72. lieTables[1].style.display="block";
  73. lieTables[1].style.backgroundColor="#b3b3b3";
  74. break;
  75. case 3:
  76. src="homePage_3.html";
  77. lieTables[2].style.display="block";
  78. lieTables[2].style.backgroundColor="#b3b3b3";
  79. break;
  80. }
  81. page.src=src;
  82. }
  83. //清除tableBar的颜色
  84. function clear(){
  85. var lieTables=document.getElementsByClassName("lieTable");
  86. for(var i=0;i<lieTables.length;i++){
  87. lieTables[i].style.backgroundColor="rgba(61, 61, 61, 0.8)";
  88. }
  89. }
  90. function exit(cell){
  91. var page=document.getElementsByClassName("page")[0];
  92. if(cell.parentNode.previousElementSibling){
  93. clear();
  94. cell.parentNode.previousElementSibling.style.backgroundColor="#b3b3b3";
  95. page.src=cell.parentNode.previousElementSibling.src;
  96. cell.parentNode.style.display="none";
  97. }
  98. }
  99. function changePage(cell){
  100. getPage();
  101. var page=document.getElementsByClassName("page")[0];
  102. clear();
  103. cell.parentNode.style.backgroundColor="#b3b3b3";
  104. page.src=cell.parentNode.src;
  105. }
  106. function quit(){
  107. sessionStorage.clear();
  108. location.assign("login.html");
  109. }
  110. //控制弹窗的状态
  111. function changeSate(id){
  112. var cell=document.getElementById(id);
  113. if(cell.style.display=="none"){
  114. cell.style.display="block";
  115. }else{
  116. cell.style.display="none";
  117. }
  118. }
  119. function changeThePassWord(){
  120. var userName=sessionStorage.userName;
  121. var oPw=document.getElementById("oPw").value;
  122. var nPw=document.getElementById("nPw").value;
  123. var qPw=document.getElementById("qPw").value;
  124. var userArrayStr=localStorage.userInfo||"";
  125. userArray=eval("("+userArrayStr+")");
  126. var j=0;
  127. for(var j=0;j<userArray.length;j++){
  128. if((userName==userArray[j].userName)&&(oPw==userArray[j].passWord)&&(qPw==nPw)){
  129. userArray[j].passWord=nPw;
  130. var str=JSON.stringify(userArray);
  131. localStorage.userInfo=str;
  132. changeSate("changePassword");
  133. break;
  134. }
  135. }
  136. if(j>=userArray.length){
  137. alert("信息错误!");
  138. }
  139. }
  140. </script>
  1. 、table页的展示

    <script>

    1. **var *onePageNumber***=20;
    2. *//页数
    • var index=0;

      *//总页数

    • var pageNumber=1;
  1. *//控制弹窗的状态
  2. * **function** *changeState*(id)\{
  3. **var** cell=**document**.getElementById(id);
  4. **if**(cell.**style**.**display**==**"none"**)\{
  5. cell.**style**.**display**=**"block"**;
  6. \}**else**\{
  7. cell.**style**.**display**=**"none"**;
  8. \}
  9. \}
  10. *//用户数据信息(二维数组)
  11. * **var *loadCustomerInfoArray***=\[\];
  12. *//初始化客户信息
  13. * **function** *initCustomerInfo*() \{
  14. **var** str = **localStorage**.**customerInfo**;
  15. **var** customerInfoArray= eval(**"("** \+ str \+ **")"**);
  16. *ifPage*(customerInfoArray);
  17. \}
  18. *//判断是否分页
  19. * **function** *ifPage*(customerInfoArray,clear)\{
  20. **if**(clear)\{
  21. ***index***=0;
  22. \}
  23. ***loadCustomerInfoArray***=\[\];
  24. ***pageNumber***=parseInt(customerInfoArray.**length**/20)+1;
  25. **if**(customerInfoArray.**length**>***onePageNumber***)\{
  26. **for**(**var** i=0;i<***pageNumber***;i\++)\{
  27. ***loadCustomerInfoArray***\[i\]=\[\];
  28. **for**(**var** j=0;j<20;j\++)\{
  29. **if**(customerInfoArray\[j\+i\*20\])\{
  30. ***loadCustomerInfoArray***\[i\]\[j\]=customerInfoArray\[j\+i\*20\];
  31. \}
  32. **else**\{
  33. **break**;
  34. \}
  35. \}
  36. \}
  37. *pageControl*(***index***);
  38. \}**else**\{
  39. *load*(customerInfoArray);
  40. \}
  41. **document**.getElementsByClassName(**"pageNumber"**)\[0\].**innerHTML**=**"第"**\+(***index***\+1)+**"/"**\+***pageNumber***\+**"页"**;
  42. \}
  43. **function** *load*(customerInfoArray)\{
  44. **var** table= **document**.getElementById(**"table"**);
  45. **var** tbody= table.**firstElementChild**;
  46. **var** trs = tbody.**children**;
  47. **while** (trs.**length**> 1) \{
  48. **var** trl = tbody.**lastElementChild**;
  49. tbody.removeChild(trl);
  50. \}
  51. *//导入数据
  52. * **for**(**var** i=0;i<customerInfoArray.**length**;i\++)\{
  53. **var** tr=**document**.createElement(**"tr"**);
  54. **var** td=**document**.createElement(**"td"**);
  55. td.**innerHTML**=i\+1;
  56. td.**width**=**"40px"**;
  57. td.**style**.**backgroundColor**=**"\#454545"**;
  58. td.**style**.**color**=**"white"**;
  59. tr.appendChild(td);
  60. **if**(customerInfoArray\[i\])\{
  61. **var** td0=**document**.createElement(**"td"**);
  62. td0.**innerHTML**=**"<inputclass='cCheckbox' type='checkbox'/>"**;
  63. tr.appendChild(td0);
  64. **var** td1=**document**.createElement(**"td"**);
  65. td1.**innerHTML**=customerInfoArray\[i\].**cNo**;
  66. tr.appendChild(td1);
  67. **var** td2=**document**.createElement(**"td"**);
  68. td2.**innerHTML**=customerInfoArray\[i\].**cName**;
  69. tr.appendChild(td2);
  70. **var** td3=**document**.createElement(**"td"**);
  71. td3.**innerHTML**=customerInfoArray\[i\].**cCity**;
  72. tr.appendChild(td3);
  73. **var** td4=**document**.createElement(**"td"**);
  74. td4.**innerHTML**=customerInfoArray\[i\].**cAddr**;
  75. tr.appendChild(td4);
  76. **var** td5=**document**.createElement(**"td"**);
  77. td5.**innerHTML**=customerInfoArray\[i\].**cManager**;
  78. tr.appendChild(td5);
  79. **var** td6=**document**.createElement(**"td"**);
  80. td6.**innerHTML**=customerInfoArray\[i\].**cPost**;
  81. tr.appendChild(td6);
  82. **var** td7=**document**.createElement(**"td"**);
  83. td7.**innerHTML**=customerInfoArray\[i\].**cPhone**;
  84. tr.appendChild(td7);
  85. **var** td8=**document**.createElement(**"td"**);
  86. **var** num=customerInfoArray\[i\].**cStars**\-0;
  87. **var** stars=**""**;
  88. **for**(**var** j=0;j<num;j\++)\{
  89. stars\+=**"<span style='color: \#f5b704'>★</span>"**;
  90. \}
  91. **for**(**var** j=0;j<(5\-num);j\++)\{
  92. stars\+=**"<spanstyle='color: \#686868'>★</span>"**;
  93. \}
  94. td8.**innerHTML**=stars;
  95. tr.appendChild(td8);
  96. tbody.appendChild(tr);
  97. \}
  98. \}
  99. \}
  100. *//添加用户
  101. * **function** *addCustomer*()\{
  102. **var** customerInfo=**localStorage**.**customerInfo**;
  103. **var** customerArray=eval(**"("**\+customerInfo\+**")"**);
  104. **var** cName=**document**.getElementById(**"cName"**).**value**;
  105. **var** cCity=**document**.getElementById(**"cCity"**).**value**;
  106. **var** cAddr=**document**.getElementById(**"cAddr"**).**value**;
  107. **var** cManager=**document**.getElementById(**"cManager"**).**value**;
  108. **var** cPost=**document**.getElementById(**"cPost"**).**value**;
  109. **var** cPhone=**document**.getElementById(**"cPhone"**).**value**;
  110. **var** cStars=**document**.getElementById(**"cStars"**).**value**;
  111. **var** cNo=parseInt(customerArray\[0\].**cNo**)+1\+**""**;
  112. **for**(**var** i=0;i<customerArray.**length**;i\++)\{
  113. **if**(customerArray\[i\].**cNo**>=cNo)\{
  114. cNo=parseInt(customerArray\[i\].**cNo**)+1\+**""**;
  115. \}
  116. \}
  117. **var** Customer=\{
  118. **cNo**:cNo,
  119. **cName**:cName,
  120. **cCity**:cCity,
  121. **cAddr**:cAddr,
  122. **cManager**:cManager,
  123. **cPost**:cPost,
  124. **cPhone**:cPhone,
  125. **cStars**:cStars
  126. \};
  127. customerArray.push(Customer);
  128. **var** str=**JSON**.stringify(customerArray);
  129. **localStorage**.**customerInfo**=str;
  130. *//关闭弹窗
  131. changeState*(**"addUser"**);
  132. ***index***=***pageNumber***\-1;
  133. *//刷新当前页
  134. initCustomerInfo*();
  135. alert(**"添加成功"**);
  136. \}
  137. **function** *del*()\{
  138. **var** table=**document**.getElementById(**"table"**);
  139. **var** tbody=table.**firstElementChild**;
  140. **var** trs=tbody.**children**;
  141. **var** customerInfo=**localStorage**.**customerInfo**;
  142. **var** customerInfoArray=eval(**"("**\+customerInfo\+**")"**);
  143. **for**(**var** i=0;i<trs.**length**;i\++)\{
  144. **if**(trs\[i\].**firstElementChild**.**nextElementSibling**.**firstElementChild**.**checked**)\{
  145. **for**(**var** j=0;j<customerInfoArray.**length**;j\++) \{
  146. **if** (customerInfoArray\[j\].**cNo** == trs\[i\].**firstElementChild**.**nextElementSibling**.**nextElementSibling**.**innerHTML**) \{
  147. customerInfoArray.splice(j,1);
  148. \}
  149. \}
  150. \}
  151. \}
  152. customerInfo=**JSON**.stringify(customerInfoArray);
  153. **localStorage**.**customerInfo**=customerInfo;
  154. **document**.getElementById(**"cCheckbox"**).**checked**=**false**;
  155. *initCustomerInfo*();
  156. alert(**"删除成功"**);
  157. \}
  158. **function** *selectAll*()\{
  159. **var** cCheckbox=**document**.getElementById(**"cCheckbox"**);
  160. **var** table=**document**.getElementById(**"table"**);
  161. **var** tbody=table.**firstElementChild**;
  162. **var** trs=tbody.**children**;
  163. **if**(cCheckbox.**checked**)\{
  164. **for**(**var** i=0;i<trs.**length**;i\++)\{
  165. trs\[i\].**firstElementChild**.**nextElementSibling**.**firstElementChild**.**checked**=**true**;
  166. \}
  167. \}**else**\{
  168. **for**(**var** i=0;i<trs.**length**;i\++)\{
  169. trs\[i\].**firstElementChild**.**nextElementSibling**.**firstElementChild**.**checked**=**false**;
  170. \}
  171. \}
  172. \}
  173. *//查询
  174. * **function** *search*()\{
  175. **var** sNo=**document**.getElementById(**"sNo"**).**value**;
  176. **var** sName=**document**.getElementById(**"sName"**).**value**;
  177. **var** select=**document**.getElementById(**"select"**).**value**;
  178. **var** customerInfo=**localStorage**.**customerInfo**;
  179. **var** customerInfoArray=eval(**"("**\+customerInfo\+**")"**);
  180. **var** temCustomerInfoArray=\[\];
  181. **for**(**var** i=0;i<customerInfoArray.**length**;i\++)\{
  182. **if**(sNo)\{
  183. **if**(sName)\{
  184. **if**((customerInfoArray\[i\].**cNo**==sNo)&&(customerInfoArray\[i\].**cName**.split(sName).**length**>1))\{
  185. temCustomerInfoArray.push(customerInfoArray\[i\]);
  186. \}
  187. \}**else**\{
  188. **if**(customerInfoArray\[i\].**cNo**==sNo)\{
  189. temCustomerInfoArray.push(customerInfoArray\[i\]);
  190. \}
  191. \}
  192. \}**else if**(sName)\{
  193. **if** (customerInfoArray\[i\].**cName**.split(sName).**length**>1)\{
  194. temCustomerInfoArray.push(customerInfoArray\[i\]);
  195. \}
  196. \}**else**\{
  197. temCustomerInfoArray=customerInfoArray;
  198. \}
  199. \}
  200. **if**(select!=0)\{
  201. **var** mNewArray=temCustomerInfoArray;
  202. **for**(**var** i=0;i<mNewArray.**length**;i\++)\{
  203. **if**(mNewArray\[i\])\{
  204. **if**(mNewArray\[i\].**cStars**!=select)\{
  205. mNewArray\[i\]=**""**;
  206. \}
  207. \}
  208. \}
  209. temCustomerInfoArray=\[\];
  210. **for**(**var** i=0,j=0;i<mNewArray.**length**;i\++)\{
  211. **if**(mNewArray\[i\]!=**""**)\{
  212. temCustomerInfoArray\[j\++\]=mNewArray\[i\];
  213. \}
  214. \}
  215. \}
  216. *ifPage*(temCustomerInfoArray,**true**);
  217. \}
  218. *//页数管理
  219. * **function** *pageControl*(index)\{
  220. *load*(***loadCustomerInfoArray***\[index\]);
  221. \}
  222. *//翻页
  223. * **function** *flip*(id)\{
  224. **switch** (id)\{
  225. **case** 0:
  226. **if**(***index***>=1)\{
  227. ***index***\--;
  228. *load*(***loadCustomerInfoArray***\[***index***\]);
  229. \}
  230. **break**;
  231. **case** 1:
  232. **if**(***index***<***pageNumber***\-1)\{
  233. ***index***\++;
  234. *load*(***loadCustomerInfoArray***\[***index***\]);
  235. \}
  236. **break**;
  237. \}
  238. **document**.getElementsByClassName(**"pageNumber"**)\[0\].**innerHTML**=**"第"**\+(***index***\+1)+**"/"**\+***pageNumber***\+**"页"**;
  239. \}
  240. **var *myX***=0;
  241. **var *myY***=0;
  242. **var *go***=**false**;
  243. **var *addUser***;
  244. **var *offsetx***=0;
  245. **var *offsety***=0;
  246. **document**.onmousemove=**function**(e)\{
  247. **var** cont=**document**.getElementById(**"cont"**);
  248. ***myX***= e.**clientX**;
  249. ***myY***= e.**clientY**;
  250. **if**(***go***)\{
  251. ***addUser***.**style**.**left**=***myX***\-***offsetx***\+**"px"**;
  252. ***addUser***.**style**.**top**=***myY***\-***offsety***\+**"px"**;
  253. *//限定位置
  254. * **if**(parseFloat(***addUser***.**style**.**left**)<0)***addUser***.**style**.**left**=0\+**"px"**;
  255. **if**(parseFloat(***addUser***.**style**.**top**)<0)***addUser***.**style**.**top**=0\+**"px"**;
  256. **if**(parseFloat(parseFloat(***addUser***.**style**.**left**)+***addUser***.**offsetWidth**)>cont.**offsetWidth**)\{
  257. ***addUser***.**style**.**left**=cont.**offsetWidth**\-***addUser***.**offsetWidth**\+**"px"**;
  258. \}
  259. **if**(parseFloat(parseFloat(***addUser***.**style**.**top**)+***addUser***.**offsetHeight**)>cont.**offsetHeight**\-30)\{
  260. ***addUser***.**style**.**top**=cont.**offsetHeight**\-***addUser***.**offsetHeight**\-30\+**"px"**;
  261. \}
  262. \}
  263. \};
  264. **document**.onmouseup=**function**()\{
  265. ***go***=**false**;
  266. \};
  267. **window**.onload=**function**()\{
  268. ***addUser***=**document**.getElementById(**"addUser"**);
  269. **var** addUserTop=**document**.getElementById(**"addUserTop"**);
  270. *initCustomerInfo*();
  271. *//鼠标按下
  272. * ***addUser***.onmousedown=**function**(e)\{
  273. **if**(e.**target**==addUserTop)\{
  274. ***go***=**true**;
  275. ***offsetx***= e.**offsetX**;
  276. ***offsety***= e.**offsetY**;
  277. \}
  278. \};
  279. *//失去焦点
  280. * ***addUser***.onblur=**function**()\{
  281. ***go***=**false**;
  282. \};
  283. \};
  284. </**script**>

发表评论

表情:
评论列表 (有 0 条评论,313人围观)

还没有评论,来说两句吧...

相关阅读

    相关 JavaScript(JS网页--tab栏制作

    JS网页–tab栏制作 在网页的制作中,通常会使用到tab栏,例如淘宝,商品详情,规格参数和累计评价三个栏,点击不同的栏下面出现的内容不同。在这样的设计中,JS可以做到。

    相关 js制作简单计算器

    在学校学习过程中,老师总是让我们做各种各样小案例(demo)。但是我们在做的过程,总会遇到一些问题,会使我们绞尽脑汁。那让我们一起来看看这个案例吧! 先看看效果 ![在