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..

查询

$(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 回答