Blogger Information
Blog 16
fans 0
comment 0
visits 9639
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
固定导航栏|可编辑表格
坨坨
Original
491 people have browsed it

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. </head>
  7. <style>
  8. body{
  9. margin: 0;
  10. padding: 0;
  11. height: 1024px;
  12. }
  13. nav{
  14. margin-top: 40px;
  15. position: relative;
  16. width: 100vw;
  17. height: 40px;
  18. background-color: #90D7EC;
  19. text-align: center;
  20. line-height: 40px;
  21. z-index: 9;
  22. }
  23. table{
  24. margin:100px auto;
  25. width: 500px;
  26. border-collapse: collapse;
  27. }
  28. tr,th,td{
  29. border: 1px solid green;
  30. margin: 0;
  31. padding: 0;
  32. text-align: center;
  33. }
  34. td>input{
  35. height: 100%;
  36. width: 80%;
  37. border: none;
  38. outline: none;
  39. }
  40. </style>
  41. <body>
  42. <nav id="navObj">固定导航栏</nav>
  43. <table>
  44. <tr>
  45. <th>名称</th>
  46. <th>内容</th>
  47. </tr>
  48. <tr>
  49. <td>
  50. php中文网
  51. </td>
  52. <td>
  53. 学习家园
  54. </td>
  55. </tr>
  56. <tr>
  57. <td>
  58. php中文网
  59. </td>
  60. <td>
  61. 学习家园
  62. </td>
  63. </tr>
  64. </table>
  65. </body>
  66. <script>
  67. var tdObj = document.getElementsByTagName('td');
  68. for(let i=0;i<tdObj.length;i++){
  69. tdObj[i].addEventListener('click',function(){
  70. edit(this)
  71. })
  72. }
  73. function edit(i) {
  74. var inputlen = document.getElementsByTagName('input').length
  75. var oldValue = i.innerHTML;
  76. if (inputlen ==1){
  77. var textBox = document.createElement("INPUT");
  78. textBox.type = "text";
  79. textBox.value = i.innerHTML;
  80. var timer;
  81. i.innerHTML = '';
  82. i.appendChild(textBox)
  83. textBox.select();
  84. setTimeout(function () {
  85. timer =textBox.onblur =function () {
  86. i.innerHTML = textBox.value
  87. }
  88. },2000)
  89. textBox.onkeydown = function (e) {
  90. if (e.keyCode == 13){
  91. clearTimeout(timer);
  92. i.innerHTML= textBox.value;
  93. }
  94. if (e.keyCode ==27){
  95. clearTimeout(timer)
  96. i.innerHTML = oldValue;
  97. }
  98. }
  99. }
  100. }
  101. var navObj = document.getElementById('navObj');
  102. window.onscroll = function () {
  103. if ( document.documentElement.scrollTop>40){
  104. navObj.style.top = (document.documentElement.scrollTop-40)+ 'px';
  105. }
  106. }
  107. </script>
  108. </html>
Correcting teacher:autoloadautoload

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post