【问题标题】:popup window when hover over a table cell html javascript将鼠标悬停在表格单元格上时弹出窗口 html javascript
【发布时间】:2012-07-06 07:17:05
【问题描述】:

我正在编写一个 JavaScript 应用程序,我发现了一个不错的库 qtip2。我的目标是当用户将鼠标悬停在表格中的每个单元格上时,会显示不同的信息。我上面提到的那个库可以在一个小的弹出窗口中显示信息。但是,我不确定如何在其他中设置此功能以在将鼠标悬停在每个单元格上时显示每个单元格的特定内容。有人知道我该怎么做吗?

function showInfo()
    {
            $('#demo-mouse').qtip({
                content : 'I position myself at the current mouse position',
                position : {
                    my : 'top left',
                    target : 'mouse',
                    viewport : $(window),       //keep it on-screen at all time if possible
                    adjust : {
                        x : 10, y : 10
                    }
                },
                hide : {
                    fixed : true                // Helps to prevent the tooltip from hiding occassionaly when tracking!
                },
                style : 'ui-tooltip-shadow'
        });
    }

【问题讨论】:

    标签: javascript html css


    【解决方案1】:

    您可以使用扩展的content 属性并在要显示提示的元素中使用类:

    $('.selector').qtip({
        content: {
            text: function(api) {
                // Retrieve content from custom attribute of the $('.selector') elements.
                return $(this).attr('data-tip');
            }
        }
    });
    

    【讨论】:

    • 非常感谢您的回答。在我给你答案之前的最后一件事。如何修改我的 <td> 以拥有您提到的 .selector
    • 只需为每个<td class="selectorOrAnythingYouWant"> 添加一个class 属性或向表中添加一个类或ID,然后更改此代码中的选择器以匹配:<table id="MyTable">$("#MyTable td")。跨度>
    • 我确实做了你建议的那些改变,但是它们不起作用。 <td class="selector" style="background-color: rgb(0, 191, 255);">1</td><td class="selector" style="background-color: rgb(0, 191, 255);">1</td>
    • 刷新我哥的时候就不行了。但是,当我从 firebug 终端调用该函数时,它开始工作,想知道为什么。
    • 您只需在 $(document).ready() 事件上调用它即可在加载时触发它。
    猜你喜欢
    • 2020-08-17
    • 2020-09-20
    • 2015-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-19
    • 2019-12-13
    • 2013-03-06
    相关资源
    最近更新 更多