$('#button').click(function() {
alert($('.column').val());
});
の最初、2 番目、または 3 番目の要素を取得するにはどうすればよい.column
ですか?
$('#button').click(function() {
alert($('.column').eq(0).val()); // first element
alert($('.column').eq(1).val()); // second
alert($('.column').eq(2).val()); // third
});
私はセレクター文字列が好きなので、通常これを行います。
$('.column:eq(3)') // Fourth .column element
Slice() 関数を使用します: http://api.jquery.com/slice/
質問を参照してください: jQuery で要素の範囲を選択する方法
$('.column').slice(0, 2).each(function() {
$(this).val(); /* my value */
});
:lt
(未満の)セレクターを使用して、インデックスの下0, 1, and 2
にあるすべての要素を示すことで、必要なことを伝えることができます。.column
3
$("#button").on("click", function(){
$(".column:lt(3)").each(function(){
alert( this.value );
});
});
デモ: http: //jsbin.com/icevih/edit#javascript,html