0

div name を使用して、div id とその子クラス名を取得する必要があります。ただし、div ID は常に異なり、一意になります。

HTML

<div class="diagram" id="12" >
<div class="121">
    ...     
</div>
</div>

<div class="diagram" id="133" >
<div class="33">
    ...     
</div>
</div>

<div class="diagram" id="199" >
<div class="77">
    ...     
</div>
</div> So on..

Jクエリ

$(function(){ 
//i need to pass  to values to the function in the following way

o.circle("12","121");
o.circle("133","33"); 
o.circle("199","77"); 

//So on..
});

私を助けてください

4

2 に答える 2

3
$('div.diagram').each(function() {

  // this.id -> get the id of parent i.e div.diagram
  // $('div:first', this) -> get the first child of diagram, here this refers to diagram
  // $('div:first', this).attr('class') -> get the class name of child div

  o.circle(this.id, $('div:first', this).attr('class'));
});

イベントでこれを試してみたい場合は、次を試してください。

例:

// I assumed a click event

$('div.diagram').on('click', function() {
  o.circle(this.id, $('div:first', this).attr('class'));
});
于 2012-05-22T11:53:07.103 に答える
0

あなたはこれを使うことができます。それは私にとってうまく働いています。

                 $('div.diagram').on('event_name', function() { // use click, hover, change, focus at the place of event_name whatever you need
                   o.circle(this.id, $('div:first', this).attr('class'));
                 });
于 2012-05-22T12:18:45.943 に答える