简体   繁体   English

即使事件触发,jQuery简单的工具提示也不会显示?

[英]jQuery simple tooltip not showing even though event triggered?

first of, this is what I got: 首先,这是我得到的:

        $('div.pickup').load('/pages/pickup.php?pickup=' + pickup, function() {

            $('div.pickup').fadeIn(300);

            var box = $('#tooltip');
            var trigger = $('.tip');

            trigger.hover(function(e) { 
                alert('Showing tooltip with text: ' + $(this).attr('title'));
                box.text($(this).attr('title'));
                box.css({
                    'top': (e.pageY - 10) + 'px',
                    'left': (e.pageX + 20) + 'px'
                }).fadeIn(300);
            }, function() {
                box.hide();
            });

            trigger.mousemove(function(e) {
                box.css({
                    'top': (e.pageY - 10) + 'px',
                    'left': (e.pageX + 20) + 'px'
                });
            });

        });

A table header contains the 'trigger class' named .tip . 表头包含名为.tip“触发器类” Every element with that class should initiate the tooltip when hovered. 悬停时,具有该类的每个元素都应启动工具提示。 The th containing the .tip -class looks like this: 包含.tip -class的th如下所示:

<th class="type red b_l b_b tip" title="test">T</th>

I expected the tooltip to show up near the mouse cursor when hovering the <th> element containing class="tip" , the hover event fired but all I got was the dialogue box from the alert() call. 我希望将鼠标悬停在包含class="tip"<th>元素上时,提示会显示在鼠标光标附近,但会触发悬停事件,但我得到的只是来自alert()调用的对话框。

The #tooltip div element is just one line in the PHP -file; #tooltip div元素只是PHP文件中的一行; <div id="tooltip"></div>

CSS: CSS:

#tooltip {
    display: none;
    position: absolute;
    z-index: 1;
    background-color: #ffffff;
    border: 1px solid #000000;
    padding: 3px;
    font-family: Consolas, monaco, monospace;
    font-size: 0.8em;
    letter-spacing: 0.1em;
    box-shadow: 0px 3px 4px #000000;
}

I'm pretty sure the tooltip aint hidden behind another element (ie. the table containing the 我很确定工具提示不会隐藏在另一个元素(即包含 ), #tooltip is the only element with a z-index manually set. ), #tooltip是唯一手动设置了z-index元素。 I even tried z-index: 999 . 我什至尝试了z-index: 999

What am I doing wrong? 我究竟做错了什么?

  • Tested in latest IE and FF versions 经过最新的IE和FF版本测试

Sorry I've to put an answer since I can't comment, can you locate the tool tip in the developer tools in FF ? 抱歉,由于我无法发表评论,我必须回答一个问题,您可以在FF开发人员工具中找到工具提示吗? It should highlight for you the location of the tool tip, and you should be able to check & set it's visibility via the JS console 它应该为您突出显示工具提示的位置,并且您应该能够通过JS控制台检查和设置其可见性

Okay, I simply removed the alert() call and out of a sudden it works. 好的,我只是删除了alert()调用,但突然间它起作用了。 I'm not sure how alert() affects the code following on it, but it seems to interrupt it at some point. 我不确定alert()如何影响后面的代码,但似乎在某些时候中断了它。

Anyways, removing the alert() which was for debug purposes fixed the problem and the tooptip shows fine in both, FF and IE . 无论如何,删除用于调试目的的alert()可以解决问题,并且tooptip在FFIE中都可以正常显示。

Though, thank you for your suggestions! 不过,谢谢您的建议!

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

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