Hiding a button in Javascript

2019-01-08 23:15发布

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?

8条回答
▲ chillily
2楼-- · 2019-01-08 23:48
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")

查看更多
Ridiculous、
3楼-- · 2019-01-08 23:53
document.getElementById('btnID').style.visibility='hidden';
查看更多
爷、活的狠高调
4楼-- · 2019-01-08 23:54

You can set its visibility property to 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>
查看更多
爷的心禁止访问
5楼-- · 2019-01-08 23:56

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

查看更多
淡お忘
6楼-- · 2019-01-08 23:56

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

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

查看更多
beautiful°
7楼-- · 2019-01-09 00:01
<script>
$('#btn_hide').click( function () {
$('#btn_hide).hide();
});
</script>
<input type="button" id="btn_hide"/>

this will be enough

查看更多
登录 后发表回答