自己写的一个网页版简易账本

墨蓝 2022-04-01 13:13 343阅读 0赞
  1. 根据毕老师的HTML+CSS+JavaScript教程自己琢磨着写出来的一个简易账本,功能很简单,但每一个字符都是自己敲出来的,清楚他们的功能,还是很有成就感的!先看下概貌吧!

1359096938_7814.JPG

***************************************************************************************************************************

看能不能直接在这里显示出来

-———————————————————————————————————————————————————————————————————————————-

















类别 金额 日期 备注
收入
支出












序号 类别 金额 日期 备注 结余

***************************************************************************************************************************

显示了但不能用 给出代码

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  5. <title>简易账本</title>
  6. <style type="text/css">
  7. table{
  8. border: red 2px solid;
  9. text-align: center;
  10. border-collapse: collapse;
  11. width: 600px;
  12. background: #CCFF99;
  13. }
  14. table td, table th{
  15. border: red 1px solid;
  16. }
  17. table th{
  18. background: #99CC33;
  19. }
  20. .one{
  21. background: #66FFFF;
  22. }
  23. .two{
  24. background: #66FF33;
  25. }
  26. .over{
  27. background: #FF66FF;
  28. }
  29. #click{
  30. background: #FF6600;
  31. }
  32. </style>
  33. <script type="text/javascript">
  34. var styleName;
  35. onload = function()
  36. {
  37. var tabNode = document.getElementById("dst");
  38. var time = new Date();
  39. //alert(time.getYear()+"-"+(time.getMonth()+1)+"-"+time.getDate());
  40. var sysTime = time.getYear()+"-"+(time.getMonth()+1)+"-"+time.getDate();
  41. //alert(sysTime);
  42. var timeText = document.getElementById("riqi");
  43. //alert(timeText.innerHTML);
  44. timeText.value = sysTime;
  45. //alert(timeText.text);
  46. var tabRows = tabNode.rows;
  47. for (var x=1; x<tabRows.length; x++)
  48. {
  49. if (x%2==1)
  50. {
  51. tabRows[x].className = "one";
  52. }
  53. else
  54. tabRows[x].className = "two";
  55. loadEvent(tabRows[x]);
  56. /*tabRows[x].onmouseover = over();
  57. tabRows[x].onmouseout = out();
  58. tabRows[x].onclick = click();
  59. */
  60. }
  61. }
  62. function loadEvent(node)
  63. {
  64. node.onmouseover = function()
  65. {
  66. styleName = this.className;
  67. this.className = "over";
  68. }
  69. node.onmouseout = function()
  70. {
  71. this.className = styleName;
  72. }
  73. node.onclick = function()
  74. {
  75. if (this.id=="click")
  76. {
  77. this.id = "";
  78. }
  79. else
  80. this.id = "click";
  81. }
  82. }
  83. /*function reload(node)
  84. {
  85. var tabNode = document.getElementById("dst");
  86. var tabRows = tabNode.rows;
  87. for (var x=1; x<tabRows.length; x++)
  88. {
  89. if (x%2==1)
  90. {
  91. tabRows[x].className = "one";
  92. }
  93. else
  94. tabRows[x].className = "two";
  95. tabRows[x].onmouseover = over();
  96. tabRows[x].onmouseout = out();
  97. tabRows[x].onclick = click();
  98. }
  99. }*/
  100. function isNotNum(num)
  101. {
  102. for (var x=0; x<num.length; x++)
  103. {
  104. var s = num.charAt(x);
  105. if (s>=0 && s<=9)
  106. {
  107. continue;
  108. }
  109. else
  110. return true;
  111. }
  112. return false;
  113. /*不是这样
  114. for (var x=0; x<num.length; x++)
  115. {
  116. if (num[x]<=0 && num[x]>=9)
  117. {
  118. continue;
  119. }
  120. else
  121. return true;
  122. }
  123. return false;
  124. */
  125. }
  126. //dstnum 目标表格序号 刚开始表格只有标题行 所以先将dstnum=0
  127. //定义一个标记 刚开始为false dstnum=0 开始添加后为TRUE
  128. var flag = false;
  129. function addList()
  130. {
  131. //var tabNode = document.getElementById("src");
  132. var shouzhi = document.getElementsByName("shouzhi");
  133. //alert(shouzhi[0].checked);
  134. var leibie = shouzhi[0].checked?true:false; //true为收入 false为支出
  135. //alert(leibie);
  136. var money = document.getElementsByName("money")[0].value;
  137. //alert(money);
  138. if (money=="")
  139. {
  140. alert("请输入金额!");
  141. return;
  142. }
  143. else if (isNotNum(money))
  144. {
  145. alert(isNotNum(money)+"你输入的"+money+"不正确");
  146. return;
  147. }
  148. else
  149. money = parseInt(money);
  150. var riqi = document.getElementById("riqi").value;
  151. //alert(riqi);
  152. var note = document.getElementById("note").value;
  153. //alert(note);
  154. /*----------------获取信息完毕 开始增加-------------------*/
  155. var tabNode = document.getElementById("dst");
  156. var tabRows = tabNode.rows;
  157. //var size = tabRows.length-1;
  158. //alert(tabRows.length);
  159. var cols = tabRows[tabRows.length-1].cells;
  160. var dstnum, jieyu;
  161. if (!flag)
  162. {
  163. dstnum = 0;
  164. jieyu = money;
  165. flag = true;
  166. }
  167. else
  168. {
  169. dstnum = parseInt(cols[0].innerText);
  170. var srcJieyu = parseInt(cols[cols.length-1].innerText);
  171. jieyu = leibie?srcJieyu+money:srcJieyu-money;
  172. }
  173. //alert(dstnum);
  174. var dstlei = leibie?"收入":"支出";
  175. //alert(jieyu);
  176. //var newNode = document.createElement("tr");
  177. //alert(newNode.nodeName);
  178. var newNode = tabNode.insertRow(tabRows.length);
  179. for (var x=0; x<cols.length; x++)
  180. {
  181. //alert(x);
  182. newNode.insertCell();
  183. }
  184. if (dstnum%2==1)
  185. //tabRows[tabRows.length-1].childNodes[0].className = "two";
  186. newNode.className = "one";
  187. else
  188. newNode.className = "two";
  189. loadEvent(newNode);
  190. //alert(newNode.cells[0].innerText+"::"+tabRows[tabRows.length-1].className+"::"+newNode.className);
  191. //newNode.height = 99;
  192. /*这些事件加不上吗?
  193. newNode.onmouseover = over();
  194. newNode.onmouseout = out();
  195. newNode.onclick = click();
  196. */
  197. var newcols = newNode.cells;
  198. //alert(newcols.length);
  199. newcols[0].innerText = dstnum+1;
  200. newcols[1].innerText = dstlei;
  201. newcols[2].innerText = money;
  202. newcols[3].innerText = riqi;
  203. newcols[4].innerText = note;
  204. newcols[5].innerText = jieyu;
  205. /*内容还真难加 怎么弄呢
  206. //var newNode = tabRows[tabRows.length];
  207. //newNode.innerHTML = "'<td>'+'(dstnum+1)'+'</td><td>'+'dstlei'+'</td><td>'+'money'+'</td><td>'+'riqi'+'</td><td>'+'note'+'</td><td>'+'jieyu'+'</td>'";
  208. //(newNode.cells)[0].innerText = 55;
  209. //cols[0].innerText = 999;
  210. alert(newNode.nodeName);
  211. newNode.height = 99;
  212. //newNode.innerText = "点击斤斤计较斤斤计较斤斤计较斤斤计较斤斤计较经济";
  213. newNode.innerHTML = "<td>的的点对点的的的点对点的</td>";
  214. */
  215. }
  216. </script>
  217. </head>
  218. <body>
  219. <!--简易账本-->
  220. <table id="src">
  221. <tr>
  222. <th>类别</th>
  223. <th>金额</th>
  224. <th>日期</th>
  225. <th>备注</th>
  226. <td rowspan=2><input type="button" value="添加记录" οnclick="addList()" /></td>
  227. </tr>
  228. <tr>
  229. <td><input type="radio" name="shouzhi" value="shouru" checked="checked" />收入<br/>
  230. <input type="radio" name="shouzhi" value="zhichu" />支出
  231. </td>
  232. <td><input type="text" name="money" size="15" /></td>
  233. <td><input type="text" id="riqi" size="15" /></td>
  234. <td><textarea id="note" size="15"></textarea><!--input type="text" name="note" /--></td>
  235. </tr>
  236. </table>
  237. <hr />
  238. <table id="dst">
  239. <tr>
  240. <th>序号</th>
  241. <th>类别</th>
  242. <th>金额</th>
  243. <th>日期</th>
  244. <th>备注</th>
  245. <th>结余</th>
  246. </table>
  247. </body>
  248. </html>

发表评论

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

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

相关阅读