gpt4 book ai didi

jquery-ui - 单击时保持 jQuery 工具提示打开?

转载 作者:行者123 更新时间:2023-12-01 05:22:39 24 4
gpt4 key购买 nike

我想使用 jQuery UI 的工具提示功能,但是我需要它,所以当您单击一个元素(在我的情况下是图像)时,工具提示会保持打开状态。这能做到吗?我看不到任何选项。

http://api.jqueryui.com/tooltip/

更新这里是我的代码。我认为第 4 行应该有效,但遗憾的是没有:

HTML

<img class="jqToolTip" src="/query.gif" title="Text for tool tip here">

Javascript
$('.jqToolTip').tooltip({
disabled: false
}).click(function(){
$(this).tooltip( "open" );
// alert('click');
}).hover(function(){
// alert('mouse in');
}, function(){
// alert('mouse out');
});

最佳答案

我试图解决完全相同的问题,但在任何地方都找不到答案。经过 4 个多小时的搜索和试验,我终于想出了一个有效的解决方案。

我所做的是这样的:

  • 如果状态被点击,立即停止传播
  • 添加了一个点击处理程序来跟踪状态


  • //This is a naive solution that only handles one tooltip at a time
    //You should really move clicked as a data attribute of the element in question
    var clicked;
    var tooltips = $('a[title]').on('mouseleave focusout mouseover focusin', function(event) {
    if (clicked) {
    event.stopImmediatePropagation();
    }
    }).tooltip().click(function() {
    var $this = $(this);
    var isOpen = $this.data('tooltip');
    var method = isOpen ? 'close' : 'open';
    $this.tooltip(method);
    //verbosity for clarity sake, yes you could just use !isOpen or clicked = (method === 'open')
    if (method === 'open') {
    clicked = true;
    } else {
    clicked = false;
    }
    $this.data('tooltip', !isOpen);
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/themes/redmond/jquery-ui.css" rel="stylesheet" />
    <a href="#" title="That's what this widget is">Tooltips</a>


    希望这将有助于 future 的谷歌员工。

    部分感谢 this post

    关于jquery-ui - 单击时保持 jQuery 工具提示打开?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15664526/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com