在 Javascript 中隐藏按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8685107/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hiding a button in Javascript
提问by dualCore
In my latest program, there is a button that displays some input popup boxes when clicked. After these boxes go away, how do I hide the button?
在我最新的程序中,有一个按钮,单击时会显示一些输入弹出框。这些框消失后,如何隐藏按钮?
回答by Philippe
You can set its visibility
propertyto hidden
.
您可以将其visibility
属性设置为hidden
。
Here is a little demonstration, where one button is used to toggle the other one:
这是一个小演示,其中一个按钮用于切换另一个按钮:
<input type="button" id="toggler" value="Toggler" onClick="action();" />
<input type="button" id="togglee" value="Togglee" />
<script>
var hidden = false;
function action() {
hidden = !hidden;
if(hidden) {
document.getElementById('togglee').style.visibility = 'hidden';
} else {
document.getElementById('togglee').style.visibility = 'visible';
}
}
</script>
回答by BennyMathison
visibility=hidden
is very useful, but it will still take up space on the page. You can also use
非常有用,但它仍然会占用页面空间。你也可以使用
display=none
because that will not only hide the object, but make it so that it doesn't take up space until it is displayed. (Also keep in mind that display's opposite is "block," not "visible")
因为这不仅会隐藏对象,而且会使其在显示之前不占用空间。(还要记住,显示的反面是“块”,而不是“可见”)
回答by Dominic Green
Something like this should remove it
像这样的东西应该删除它
document.getElementById('x').style.visibility='hidden';
If you are going to do alot of this dom manipulation might be worth looking at jquery
如果你打算做很多这种 dom 操作可能值得看看 jquery
回答by Mo3z
document.getElementById('btnID').style.visibility='hidden';
回答by diracdeltafunk
回答by Anand Dwivedi
when you press the button so it should call function that will alert message. so after alert put style visible
property .
you can achieve it using
当您按下按钮时,它应该调用将警告消息的函数。所以在警报放style visible
财产之后。你可以使用
function OpenAlert(){
alert("Getting the message");
document.getElementById("getMessage").style.visibility="hidden";
}
<input type="button" id="getMessage" name="GetMessage" value="GetMessage" onclick="OpenAlert()"/>
Hope this will help . Happy to help
希望这会有所帮助。乐于帮助
回答by Sanjun Dev
<script>
$('#btn_hide').click( function () {
$('#btn_hide).hide();
});
</script>
<input type="button" id="btn_hide"/>
this will be enough
这就足够了
回答by Wes Crow
If you are not using jQuery I would suggest using it. If you do, you would want to do something like:
如果您不使用 jQuery,我建议您使用它。如果你这样做,你会想要做这样的事情:
$( 'button' ).on(
'click'
function ( )
{
$( this ).hide( );
}
);