怎么实现点击一个按钮后让它消失?

tang466545321 2011-11-13 09:56:21
我的代码如下,我想要的效果是点击任一按钮“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>
...全文
1800 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
p2227 2011-11-13
  • 打赏
  • 举报
回复
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>
tang466545321 2011-11-13
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 hjywyj 的回复:]
display="none"
visibility="hidden"
都可以
[/Quote]

这两个属性我知道,谁能给出具体的实现代码啊,感激不尽。
  • 打赏
  • 举报
回复
display="none"
visibility="hidden"
都可以
tang466545321 2011-11-13
  • 打赏
  • 举报
回复
明白了,谢谢,那有没有什么好的方法能实现我随机点击哪个按钮它都会隐藏呢?
David_0328 2011-11-13
  • 打赏
  • 举报
回复
你单击增加一个按钮, 按钮的ID全叫"be", 然后你点击hiddenButton 按钮
document.getElementById("be").style.display="none";
, 一个元素的ID名必须在页面内是唯一的, 当你存在多个同名的ID元素时, 后面的会把前面的给覆盖了, 则就当然只能隐藏最后一个按钮了
tang466545321 2011-11-13
  • 打赏
  • 举报
回复
点击value=gg的按钮后可以增加一直增加按钮‘1’,最后一个按钮是指最后一个增加上去的那个
hellNo 2011-11-13
  • 打赏
  • 举报
回复
什么叫最后一个消失?你难道有好几个1的按钮吗?
tang466545321 2011-11-13
  • 打赏
  • 举报
回复
谢谢大家,七楼的效果是我想要的。

87,990

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧