简体   繁体   English

qtip2气球和php表:每行的气球内容不同吗?

[英]qtip2 balloons and php tables: different balloon content for each row?

I'm trying to use the qtip2 jquery plugin to make little tooptips/balloons with content inside them. 我正在尝试使用qtip2 jquery插件来制作带有内部内容的tooptips / balloons。 Here's their .js and .css files: 这是他们的.js和.css文件:

http://qtip2.com/download http://qtip2.com/download

I want it to work with tables that are populated by php from mysql. 我希望它与由mysql的php填充的表一起使用。 I'm doing the table like this: 我正在做这样的表:

 <tbody>
    <?php while($row = MySQL_fetch_array($result)): ?>
        <tr>
            <td title="lname" width="100px">
                <div style="width:100px; overflow:hidden;">
                    <?php echo(htmlentities($row['last_name'])); ?>
                </div>
            </td>
            <td title="fname" width="100px">
                <div style="width:100px; overflow:hidden;">
                    <?php echo(htmlentities($row['first_name'])); ?>
                </div>
            </td>    
            <td width="100px">
                <div style="width:100px; overflow:hidden;">
                    <?php echo(htmlentities($row['u_name'])); ?>
                </div>
            </td>  
            <td width="100px">
                <div style="width:150px; overflow:hidden;">
                    <?php echo(htmlentities($row['skype_id'])); ?>
                </div>
            </td>
       </tr>
    <?php endwhile; ?>
</tbody>

all the ugly divs are there to make it look more aligned. 所有丑陋的div都在那里使它看起来更加对齐。 anyway...here's the script for the tooltip: 无论如何...这是工具提示的脚本:

        <script>$('td[title]').qtip({
                    show:'click',
                    hide:'unfocus',
                    content: {
                        text: "<?php echo(htmlentities($row['last_name'])); ?>"
                    }

                }); 
        </script>

The problem is...I can only get it to display the same friggin content for every cell with 'title'. 问题是...我只能让它为每个带有“标题”的单元格显示相同的原始内容。 I want the balloon to display content specific to each $row. 我希望气球显示特定于每个$ row的内容。 Any idea how I can accomplish this? 知道我该如何做到吗?

As per the documentation : 根据文档

You can also specify an function that returns the content, which will be run on each consecutive show event. 您还可以指定一个返回内容的函数,该函数将在每个连续的show事件上运行。 This function can return both static textual content (text or HTML), or a Deferred object (see below) The function is executed with it's scope as the target element, along with both an event and api argument(s) respectively. 此函数可以返回静态文本内容(文本或HTML),也可以返回Deferred对象(请参见下文)。该函数以其作用域为目标元素以及事件和api参数分别执行。

So you can do this: 因此,您可以执行以下操作:

content: {
    text: function() {return $(this).closest("tr").find("[title=lname]").text();}
}

The idea is, starting from the target element scope ( this ) which we know is a td[title] , to somehow produce the text for the tooltip. 这个想法是,从我们知道是td[title]的目标元素范围( this )开始,以某种方式生成工具提示的文本。 Since the only instance of that text in your markup is inside the td[title=lname] , the code finds that and returns its text. 由于标记中该文本的唯一实例位于td[title=lname] ,因此代码会找到该文本并返回其文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM