html中按钮的隐藏属性

前端之家收集整理的这篇文章主要介绍了html中按钮的隐藏属性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图在一个按钮上显示三个按钮。在按钮之前,所有三个按钮都被隐藏。我设置隐藏的属性,我也在一个按钮点击调用一个功能。问题是,当我加载页面时,所有按钮都可见。在我添加css之前,它工作得很好,我不明白问题所在。这是HTML代码
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head>
  3. <Meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <link rel="STYLESHEET" type="text/css" href="dba_style/buttons.css" />
  5. <title>Untitled Document</title>
  6.  
  7. </head>
  8. <script type="text/javascript">
  9. function change(){
  10. document.getElementById("save").hidden = "";
  11. document.getElementById("change").hidden = "";
  12. document.getElementById("cancel").hidden = "";
  13.  
  14. }
  15. </script>
  16. <body>
  17. <form name="form1" method="post" action="">
  18. <div class="buttons">
  19.  
  20. <button class="regular" name="edit" id="edit" onclick="change();">
  21. <img src="dba_images/textfield_key.png" alt=""/>
  22. Edit
  23. </button>
  24.  
  25. <button type="submit" class="positive" name="save" id="save" hidden="hidden">
  26. <img src="dba_images/apply2.png" alt=""/>
  27. Save
  28. </button>
  29.  
  30. <button class="regular" name="change" hidden="hidden" id="change">
  31. <img src="dba_images/textfield_key.png" alt=""/>
  32. change
  33. </button>
  34.  
  35. <button class="negative" name="cancel" id="cancel" hidden="hidden">
  36. <img src="dba_images/cross.png" alt=""/>
  37. Cancel
  38. </button>
  39. </div>
  40. </form>
  41. </body>
  42. </html>

这里是我正在使用的CSS。

  1. .buttons a,.buttons button{
  2. display:block;
  3. float:left;
  4. margin:0 7px 0 0;
  5. background-color:#f5f5f5;
  6. border:1px solid #dedede;
  7. border-top:1px solid #eee;
  8. border-left:1px solid #eee;
  9.  
  10. font-family:"Lucida Grande",Tahoma,Arial,Verdana,sans-serif;
  11. font-size:12px;
  12. line-height:130%;
  13. text-decoration:none;
  14. font-weight:bold;
  15. color:#565656;
  16. cursor:pointer;
  17. padding:5px 10px 6px 7px; /* Links */
  18. }
  19. .buttons button{
  20. width:auto;
  21. overflow:visible;
  22. padding:4px 10px 3px 7px; /* IE6 */
  23. }
  24. .buttons button[type]{
  25. padding:5px 10px 5px 7px; /* Firefox */
  26. line-height:17px; /* Safari */
  27. }
  28. *:first-child+html button[type]{
  29. padding:4px 10px 3px 7px; /* IE7 */
  30. }
  31. .buttons button img,.buttons a img{
  32. margin:0 3px -3px 0 !important;
  33. padding:0;
  34. border:none;
  35. width:16px;
  36. height:16px;
  37. }
  38.  
  39. /* STANDARD */
  40.  
  41. button:hover,.buttons a:hover{
  42. background-color:#dff4ff;
  43. border:1px solid #c2e1ef;
  44. color:#336699;
  45. }
  46. .buttons a:active{
  47. background-color:#6299c5;
  48. border:1px solid #6299c5;
  49. color:#fff;
  50. }
  51.  
  52. /* POSITIVE */
  53.  
  54. button.positive,.buttons a.positive{
  55. color:#529214;
  56. }
  57. .buttons a.positive:hover,button.positive:hover{
  58. background-color:#E6EFC2;
  59. border:1px solid #C6D880;
  60. color:#529214;
  61. }
  62. .buttons a.positive:active{
  63. background-color:#529214;
  64. border:1px solid #529214;
  65. color:#fff;
  66. }
  67.  
  68. /* NEGATIVE */
  69.  
  70. .buttons a.negative,button.negative{
  71. color:#d12f19;
  72. }
  73. .buttons a.negative:hover,button.negative:hover{
  74. background:#fbe3e4;
  75. border:1px solid #fbc2c4;
  76. color:#d12f19;
  77. }
  78. .buttons a.negative:active{
  79. background-color:#d12f19;
  80. border:1px solid #d12f19;
  81. color:#fff;
  82. }
  83.  
  84. /* REGULAR */
  85.  
  86. button.regular,.buttons a.regular{
  87. color:#336699;
  88. }
  89. .buttons a.regular:hover,button.regular:hover{
  90. background-color:#dff4ff;
  91. border:1px solid #c2e1ef;
  92. color:#336699;
  93. }
  94. .buttons a.regular:active{
  95. background-color:#6299c5;
  96. border:1px solid #6299c5;
  97. color:#fff;
  98. }

我可以做什么改变,以便当我点击编辑它设置三个按钮的隐藏属性false。提前致谢。

解决方法

如果您进行以下更改,它也可以不使用jQuery:

>将type =“button”添加到编辑按钮,以不触发提交表单。
>将change()函数名称更改为其他任何东西。
>不要使用hidden =“hidden”,改用CSS:style =“display:none;”。

以下代码适用于我:

  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head>
  3. <Meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <link rel="STYLESHEET" type="text/css" href="dba_style/buttons.css" />
  5. <title>Untitled Document</title>
  6. </head>
  7. <script type="text/javascript">
  8. function do_change(){
  9. document.getElementById("save").style.display = "block";
  10. document.getElementById("change").style.display = "block";
  11. document.getElementById("cancel").style.display = "block";
  12. }
  13. </script>
  14. <body>
  15. <form name="form1" method="post" action="">
  16. <div class="buttons">
  17.  
  18. <button type="button" class="regular" name="edit" id="edit" onclick="do_change(); return false;">
  19. <img src="dba_images/textfield_key.png" alt=""/>
  20. Edit
  21. </button>
  22.  
  23. <button type="submit" class="positive" name="save" id="save" style="display:none;">
  24. <img src="dba_images/apply2.png" alt=""/>
  25. Save
  26. </button>
  27.  
  28. <button class="regular" name="change" id="change" style="display:none;">
  29. <img src="dba_images/textfield_key.png" alt=""/>
  30. change
  31. </button>
  32.  
  33. <button class="negative" name="cancel" id="cancel" style="display:none;">
  34. <img src="dba_images/cross.png" alt=""/>
  35. Cancel
  36. </button>
  37. </div>
  38. </form>
  39. </body>
  40. </html>

猜你在找的HTML相关文章