简体   繁体   English

HTML中的自毁按钮

[英]self destruct button in html

Is it possible to destroy an html button. 是否有可能破坏一个html按钮。 If it is clicked because it already served its purpose after clicking. 如果单击,因为它在单击后已经达到了目的。

您可以使用JavaScript:

<button onclick="this.parentNode.removeChild(this)">Label</button>

Yes, it is possible, by using JavaScript to set its CSS property "display" to "none". 是的,可以通过使用JavaScript将其CSS属性“ display”设置为“ none”来实现。

See also Seven ways to toggle an element with JavaScript . 另请参见使用JavaScript切换元素的七种方法

我想你也可以做到

<input type="button" onclick="this.style.visibility='hidden';">

Yes, you can disable or hide it. 是的,您可以禁用或隐藏它。 Example: 例:

<input type="button" onclick="this.disabled=true;" />

However, if you do this to the submit button, it may not work properly. 但是,如果对“提交”按钮执行此操作,则它可能无法正常工作。 The value for the button will not be included in the form data, so if the server looks for the button data to find out what it was that caused the form to submit, it won't find it. 按钮的值将不包含在表单数据中,因此,如果服务器寻找按钮数据以找出导致表单提交的原因,它将找不到它。

是的,您可以这样做:

<input type="button" onclick="this.style.display = 'none';">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM