jQuery-隐藏除第一个元素外的所有元素 [英] jQuery - hide all elements except first one

查看:702
本文介绍了jQuery-隐藏除第一个元素外的所有元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有10个按钮.我想隐藏除第一个按钮以外的所有按钮.

Let's say I have 10 buttons. I want to hide all the buttons except the first one.

我正在尝试使用jQuery中的each()来实现它,但是它不起作用.

Im trying to accomplish it using each() in jQuery but its not working.

这是我的剧本.这只是看我是否可以获取按钮索引的测试.没有出现错误.

Here's my script. This is only a test to see if I can get the index of the buttons. There are no errors appearing.

$('button').each(function(index){
    alert(index);
});

其他信息:

我的整个剧本是这个

$(function(){
   $('div#here').load('test.php'); // This is where all the buttons will come from
   $('button').each(function(index){
       alert(index);
   });
});

推荐答案

与ThiefMaster相同,但不要忘记您需要等待按钮被加载.

Same as ThiefMaster but don't forget that you need to wait for buttons to be load.

您需要使用load的回调:

You need to use the callback of load :

$(function(){
$('div#here').load('test.php', function(){
   $('button:not(:first)').hide();
}); // This is where all the buttons will come from

});

Doc: http://api.jquery.com/load/

这篇关于jQuery-隐藏除第一个元素外的所有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆