0
我創建了一個隨機的HTML頁面與內部jQuery,我試圖讓jQuery隱藏三個段落中的兩個,並做了5秒,但當我加載HTML文件,所有段落立即可見。誰能幫忙?jQuery,隱藏段落
<html>
<head>
<script src="jquery-1.9.1.js"></script>
</head>
<body>
<script>
var $ = jQuery;
$("p").each(function (idx) {
if(idx >= 1) {
$(this).hide(500);
}
});
</script>
<p>This is the first paragraph</p>
<p>This is the second paragraph</p>
<p>This is the third paragraph</p>
</body>
</html>
+1的選擇語法,而不是每個循環 – 2013-03-24 23:29:21
雖然這一選擇的作品,爲什麼不進一步簡化:'$('P:GT( 0)')。hide();'或$('p')。slice(1).hide()'?雖然+1適當的選擇器*和*時間校正。當然,原生的CSS選擇器是:$('p + p')'和'$('p〜p')',它們允許選擇器傳遞給本地'document.querySelectorAll()'(在可用的瀏覽器中)。 – 2013-03-24 23:30:53
@DavidThomas - 在我看來,這比':gt'更容易理解。 – 2013-03-24 23:33:06