tooltip不适用于动态创建的内容php

时间:2014-01-10 06:13:54

标签: javascript php jquery css tooltip

我在我的应用程序中使用工具提示,但它无法使用动态内容。

当我在静态内容上使用我的工具提示时,它可以正常工作。请参阅fiddle

Tooltip for "Featured Dealers"

但是,在动态内容上创建时,它无法正常工作。

问题:鼠标悬停时工具提示隐藏;工具提示div.tooltip不应该隐藏。 如果您想要直播,请在此处查看:http://propertydefine.com/

<script>
$(document).ready(function(){

$('[rel=tooltip]').bind('mouseover', function () {
    if ($(this).hasClass('ajax')) {
        var ajax = $(this).attr('ajax');
        $.get(ajax, function (theMessage) {
            $('<div class="tooltip">' + theMessage + '</div>').appendTo('body').fadeIn('fast');
        });
    } else {
        var theMessage = $(this).attr('content');
        $('<div class="tooltip">' + theMessage + '</div>').appendTo('body').fadeIn('fast');
    }

    $(this).bind('mousemove', function (e) {
        $('div.tooltip').css({
            'top': e.pageY - ($('div.tooltip').height() / 2) - 5,
                'left': e.pageX + 15
        });
    });
});

$(document).on('mouseout click', 'div.tooltip', function(){
    $('div.tooltip').fadeOut('slow', function(){
        $(this).remove();
    }); 
});

});
</script>

php代码:

<?php
    include 'config.php'; 
//$query = "
//SELECT UserName,firstName,lastname,Mobile_Number1,Type_cust,City,location,Company_name,company_logo FROM registration WHERE City = 'Navi Mumbai'";
$query="SELECT registration.UserName,firstName,lastname,Mobile_Number1,Type_cust,City,location,Company_name,company_logo FROM registration LEFT JOIN featureddealer on registration.UserName=featureddealer.UserName WHERE City = 'Navi Mumbai' and ActiveFlag='y'" ;
$result = mysql_query($query) or die ("Query failed");
//get the number of rows in our result so we can use it in a for loop
$numrows = (mysql_num_rows ($result));
// loop to create rows
if($numrows >= 1){
for ($r = 0; $r <= $numrows; $r++) {
// loop to create columns
while ($friendList = mysql_fetch_array($result))
 {     
 $_SESSION['firstName'] = $friendList['firstName'];

//Create table

if($friendList['company_logo'] == "")
{
$friendList['company_logo'] = "images/nophoto.jpeg";
}


echo " <tr> <td class='td2'>"; 

echo '<a href=#  alt=Image id='.$friendList['Company_name'].' class=clicker Tooltip rel=tooltip content="<div class=td2><div id=imagcon><img width=100px height=100px    src=Dealer/'.$friendList['company_logo'].' class=tooltip-image /></div> <div id=con>'.$friendList['Company_name'].'</div><div id=con> '.$friendList['location'].' '.$friendList['City'].'</div><div id=con> '.$friendList['Type_cust'].' :'.$friendList['firstName'].' '.$friendList['lastname'].'<div id=con> 9930651106 </div> </div> <div id=con> <a href=# > View All Details </a>   </div>
<br/>

  <div id=con >


  '

  ;






  ?>



  <?php

1 个答案:

答案 0 :(得分:1)

在使用之前,您必须绑定到mousemove

$(this).bind('mousemove', function (e) {
    $('div.tooltip').css({
        'top': e.pageY - ($('div.tooltip').height() / 2) - 5,
            'left': e.pageX + 15
    });
});

if ($(this).hasClass('ajax')) {
    var ajax = $(this).attr('ajax');
    $.get(ajax, function (theMessage) {
        $('<div class="tooltip">' + theMessage + '</div>').appendTo('body').fadeIn('fast');
    });
} else {
    var theMessage = $(this).attr('content');
    $('<div class="tooltip">' + theMessage + '</div>').appendTo('body').fadeIn('fast');
}