在 Javascript 中隐藏按钮

发布于 2024-12-23 07:55:59 字数 50 浏览 1 评论 0原文

在我最新的程序中,有一个按钮,单击时会显示一些输入弹出框。这些框消失后,如何隐藏按钮?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

黑色毁心梦 2024-12-30 07:55:59

您可以将其可见性属性设置为隐藏

这是一个小演示,其中一个按钮用于切换另一个按钮:

<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>

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>
北笙凉宸 2024-12-30 07:55:59
visibility="hidden"

非常有用,但它仍然会占用页面空间。您也可以使用

display="none"

它,因为这不仅会隐藏对象,而且会使其在显示之前不占用空间。 (另请记住,显示的反义词是“阻止”,而不是“可见”)

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")

灵芸 2024-12-30 07:55:59

像这样的东西应该删除它

document.getElementById('x').style.visibility='hidden';

如果你打算做很多这样的dom操作可能值得看看jquery

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

郁金香雨 2024-12-30 07:55:59
document.getElementById('btnID').style.visibility='hidden';
document.getElementById('btnID').style.visibility='hidden';
无人问我粥可暖 2024-12-30 07:55:59
//Your code to make the box goes here... call it box
box.id="foo";
//Your code to remove the box goes here
document.getElementById("foo").style.display="none";

当然,如果你要做很多这样的事情,请使用 jQuery

//Your code to make the box goes here... call it box
box.id="foo";
//Your code to remove the box goes here
document.getElementById("foo").style.display="none";

of course if you are doing a lot of stuff like this, use jQuery

那些过往 2024-12-30 07:55:59

如果该页面上的空间未被禁用,则将按钮放入 div 内。

<div id="a1">
<button>Click here</button>
</div>

使用 Jquery:

<script language="javascript">
$("#a1").hide();
</script>

使用 JS:

<script language="javascript">
document.getElementById("a1").style.visibility = "hidden";
document.getElementById("a1").style.display = "none";
</script>

If the space on that page is not disabled then put your button inside a div.

<div id="a1">
<button>Click here</button>
</div>

Using Jquery:

<script language="javascript">
$("#a1").hide();
</script>

Using JS:

<script language="javascript">
document.getElementById("a1").style.visibility = "hidden";
document.getElementById("a1").style.display = "none";
</script>
烟雨凡馨 2024-12-30 07:55:59

当您按下按钮时,它应该调用会发出警报消息的函数。所以在警报之后放置 stylevisible property 。
你可以使用它来实现

function OpenAlert(){
        alert("Getting the message");
        document.getElementById("getMessage").style.visibility="hidden";
        
    }
 <input type="button" id="getMessage" name="GetMessage" value="GetMessage" onclick="OpenAlert()"/>

希望这会有所帮助。很高兴能帮助你

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

霓裳挽歌倾城醉 2024-12-30 07:55:59
function popAlert(){
        alert("Button will be hidden on click");
        document.getElementById("getMessage").style.visibility="hidden";
        
    }
   h1 {
            color: #0000ff;
        }
<h1>KIAAT</h1>
    <b>Hiding a button in Javascript after click</b>
    <br><br>
<input type="button" id="getMessage"  value="Hide Button OnClick" onclick="popAlert()"/>

function popAlert(){
        alert("Button will be hidden on click");
        document.getElementById("getMessage").style.visibility="hidden";
        
    }
   h1 {
            color: #0000ff;
        }
<h1>KIAAT</h1>
    <b>Hiding a button in Javascript after click</b>
    <br><br>
<input type="button" id="getMessage"  value="Hide Button OnClick" onclick="popAlert()"/>

忆悲凉 2024-12-30 07:55:59

如果您不使用 jQuery,我建议您使用它。如果你这样做,你会想做类似的事情:

$( 'button' ).on(
   'click'
   function (  )
   {
       $( this ).hide(  );
   }
);

If you are not using jQuery I would suggest using it. If you do, you would want to do something like:

$( 'button' ).on(
   'click'
   function (  )
   {
       $( this ).hide(  );
   }
);
九八野马 2024-12-30 07:55:59
<script>
    $('#btn_hide').click( function () {
      $('#btn_hide').hide();
    });
</script>
<input type="button" id="btn_hide"/>

这就足够了

<script>
    $('#btn_hide').click( function () {
      $('#btn_hide').hide();
    });
</script>
<input type="button" id="btn_hide"/>

this will be enough

原野 2024-12-30 07:55:59

您可以使用此代码:

btnID.hidden = true;

You can use this code:

btnID.hidden = true;
纸伞微斜 2024-12-30 07:55:59
var start = new Date().getTime();
while ((new Date().getTime() - start) < 1000){
  } //for 1 sec delay
var start = new Date().getTime();
while ((new Date().getTime() - start) < 1000){
  } //for 1 sec delay
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文