jQuery選択要素

2683 ワード

1.1つのクラスの下にある具体的なラベルを判断する
<div id="nav">
    <a href="#">A</a>
    <a href="#">B</a>
    <a href="#">C</a>
    <a href="#">D</a>
</div>

$("#nav a").click(function(){
    var index1 = $("#nav a").index(this);
    var index2 = $("#nav a").index($(this));
    var index3 = $(this).index()
    var index3 = $(this).index("a")
    alert(index3);
    return false;
});

2.eq選択
2番目を選択
要素:
$("p:eq(1)")

3.最後の要素を選択
$(".ct-cart-price:last")

4.each遍歴ラベル
$(".ct-cart-price").each(function(){
        console.log($(this).text());
        total+=parseFloat($(this).text().substring(1));
}); 

5.現在のラベルのサブ要素を取得する
console.log($(this).children(".ct-cart-price").text());

6.inputタグのvalue値を得る
console.log($(this).children(".ct-cart-input").val());
.val("XX"):