2010-07-23 44 views
0

遍历数组,我打印每个迭代的div内容。 只要用户点击任何div内容,就会出现一个弹出窗口,并在数组弹出框中显示相应的内容。弹出的问题:没有显示正确的相应内容

下面

是我的代码,

foreach ($email as $client) 
{ 

       echo "<div class = 't'> Show more....... </div>"; 
       echo "<div class='popup_msg'>"; 
       echo $client['Email']['body']; 
       echo "</div>"; 

} 

javascript代码如下

jQuery(document).ready(function(){ 

jQuery('.t').click(function(e) 
{ 
    var height = jQuery('.popup_msg').height(); 
    var width = jQuery('.popup_msg').width(); 
    leftVal=e.pageX-(width/1.5)+"px"; 
    topVal=e.pageY-(height/13)+"px"; 

    jQuery('.popup_msg').css({left:leftVal,top:topVal}).show(); 
}); 

jQuery('.popup_msg').click(function(e) 
{ 
jQuery('.popup_msg').fadeOut('fast'); 
}); 


}); 
在上面的代码

,我想要实现的是,每当用户点击与T类股利时,相应的客户端$ [“电子邮件”] [“身体”]应该出现在弹出

回答

0

的问题是,你选择的所有.popup_msg,不仅需要一个匹配。 (“T”)。使用find()方法来获得正确的弹出式在$单击功能:

jQuery('.t').click(function(e) 
{ 
     var popup_msg = jQuery(this).find('.popup_msg'); 
     var height = popup_msg.height(); 
     var width = popup_msg.width(); 

     leftVal=e.pageX-(width/1.5)+"px"; 
     topVal=e.pageY-(height/13)+"px"; 

     popup_msg.css({left:leftVal,top:topVal}).show(); 
}); 

注:我没有测试此代码,它可能不是100%正确的,但希望你明白我的意思。