Javascript 使用 jQuery 隐藏按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12790297/
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 button using jQuery
提问by LoolKovsky
Can someone please tell me how I can hide this button after pressing it using jQuery?
有人可以告诉我如何在使用 jQuery 按下后隐藏此按钮吗?
<input type="button" name="Comanda" value="Comanda" id="Comanda" data-clicked="unclicked" />
Or this one:
或者这个:
<input type=submit name="Vizualizeaza" value="Vizualizeaza">
回答by Rikki
Try this:
尝试这个:
$('input[name=Comanda]')
.click(
function ()
{
$(this).hide();
}
);
For doing everything else you can use something like this one:
对于其他所有事情,您可以使用以下内容:
$('input[name=Comanda]')
.click(
function ()
{
$(this).hide();
$(".ClassNameOfShouldBeHiddenElements").hide();
}
);
For hidding any other elements based on their IDs, use this one:
要根据 ID 隐藏任何其他元素,请使用以下元素:
$('input[name=Comanda]')
.click(
function ()
{
$(this).hide();
$("#FirstElement").hide();
$("#SecondElement").hide();
$("#ThirdElement").hide();
}
);
回答by Blender
You can use the .hide()function bound to a clickhandler:
您可以使用.hide()绑定到click处理程序的函数:
$('#Comanda').click(function() {
$(this).hide();
});
回答by Jo?o Cunha
jQuery offers the .hide()method for this purpose. Simply select the element of your choice and call this method afterward. For example:
为此,jQuery 提供了.hide()方法。只需选择您选择的元素,然后调用此方法。例如:
$('#comanda').hide();
One can also determine how fast the transition runs by providing a durationparameter in miliseconds or string (possible values being 'fast', and 'slow'):
还可以通过提供以毫秒或字符串为单位的持续时间参数(可能的值为“快”和“慢”)来确定转换运行的速度:
$('#comanda').hide('fast');
In case you want to do something just after the element hid, you must provide a callback as a parameter too:
如果你想在元素 hid 之后做一些事情,你也必须提供一个回调作为参数:
$('#comanda').hide('fast', function() {
alert('It is hidden now!');
});
回答by David
It depends on the jQuery selectorthat you use. Since idshould be unique within the DOM, the first one would be simple:
这取决于您使用的 jQuery 选择器。因为id在 DOM 中应该是唯一的,所以第一个很简单:
$('#Comanda').hide();
The second one might require something more, depending on the other elements and how to uniquely identify it. If the nameof that particular inputis unique, then this would work:
第二个可能需要更多的东西,这取决于其他元素以及如何唯一地标识它。如果name那个特定的input是唯一的,那么这将起作用:
$('input[name="Vizualizeaza"]').hide();

