Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery-隐藏除第一个元素之外的所有元素_Jquery_Loops_Each - Fatal编程技术网

jQuery-隐藏除第一个元素之外的所有元素

jQuery-隐藏除第一个元素之外的所有元素,jquery,loops,each,Jquery,Loops,Each,假设我有10个按钮。我想隐藏除第一个按钮以外的所有按钮 我试图用jQuery中的each()来完成它,但它不起作用 这是我的剧本。这只是一个测试,看看我是否可以得到按钮的索引。没有出现错误 $('button').each(function(index){ alert(index); }); 其他信息: 我的整个剧本是这样的 $(function(){ $('div#here').load('test.php'); // This is where all the buttons

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

我试图用jQuery中的each()来完成它,但它不起作用

这是我的剧本。这只是一个测试,看看我是否可以得到按钮的索引。没有出现错误

$('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);
   });
});
使用其中一种:

$('button:not(:first)').hide();
$('button:gt(0)').hide();
使用其中一种:

$('button:not(:first)').hide();
$('button:gt(0)').hide();
试试这个:

提供更好的性能

$('button').slice(1).hide();
试试这个:

提供更好的性能

$('button').slice(1).hide();

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

您需要使用load的回调:

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

});

文档:

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

您需要使用load的回调:

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

});

医生:

谢谢!我把你的答案和编码员的结合起来了。如果可以的话,我会给你们两个正确的答案。谢谢!我把你的答案和编码员的结合起来了。如果可以的话,我会给你们两个正确的答案。