我的代码如下,我想要的效果是点击任一按钮“1”后该按钮就消失,现在的代码只能让最后一个消失,忘指教
<table>
  <tr>
    <td><button value="gg" id ="gg" onclick="presentQ(this)"></button>
     </td>
  </tr>
</table> <script>
function presentQ(e){
    e.parentNode.innerHTML += '<button  id="be" value="be" onclick="hideButtonQ()">1</button>'; 
}function hideButtonQ(){ 
document.getElementById("be").style.display="none"; 
} </script>

解决方案 »

  1.   

    点击value=gg的按钮后可以增加一直增加按钮‘1’,最后一个按钮是指最后一个增加上去的那个
      

  2.   

    你单击增加一个按钮, 按钮的ID全叫"be", 然后你点击hiddenButton 按钮document.getElementById("be").style.display="none";, 一个元素的ID名必须在页面内是唯一的, 当你存在多个同名的ID元素时, 后面的会把前面的给覆盖了, 则就当然只能隐藏最后一个按钮了
      

  3.   

    display="none"
    visibility="hidden"
    都可以
      

  4.   

    id都 不需要的<html>
    <head>
    <script>
    hide = function(obj){
    obj.style.visibility="hidden";
    }
    </script>
    </head><body>
    <input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/><input type="button" onclick="hide(this)" value="按钮"/><br/>
    </body>
    <html>