[英]jQuery - hide all elements except first one
假設我有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);
});
});
與ThiefMaster相同,但不要忘記您需要等待按鈕被加載。
您需要使用load的回調:
$(function(){
$('div#here').load('test.php', function(){
$('button:not(:first)').hide();
}); // This is where all the buttons will come from
});
文件: http : //api.jquery.com/load/
使用以下之一:
$('button:not(:first)').hide();
$('button:gt(0)').hide();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.