2011-12-16 21 views

答えて

2

あなたはjqueryの中で同じ操作を行うことができます。

$('div').each(function() { 
    if ($(this).attr('id') == '1') 
     $(this).click(function() { // handler for first div }); 

    if ($(this).attr('id') == '2') 
     $(this).click(function() { // handler for second div });\ 

    ... 
}); 
0

$('div')

これはjQueryの使用であることを行うにはdiv要素のjQueryのコレクションDocs

5

を作成します。

$("div").each(function() { 
    // 'this' is the div 
}); 

これは、同じ:

var divs = document.getElementsByTagName('div'), 
    i, 
    len, 
    div; 

for (i = 0, len = divs.length; i < len; i++) { 
    div = divs[i]; 
} 
0
var divs = jQuery('div'); 

divs.each(function(){ 
    $(this).DoSomeThing(); 

    // $(this) refers to a div 
}); 
関連する問題