dongxianghuan3587 2014-05-06 05:34
浏览 282
已采纳

带有动态内容的jQuery UI工具提示

I use jQuery UI Tooltip Widget and there is code:

  $(function() {$( document ).tooltip({  
    content: 'connecting',
    content:function(callback) {
            $.get('teacher.php?teacherid=' + link,{}, function(data) {
            callback(data);
        });
    },

  })});

On my page i have:

<div title="" onmouseover="{link=1}">Alex Brown</div>
<div title="" onmouseover="{link=2}">John Black</div>

But it doesn't work. How can i send variable to JS that Alex Brown is teacher with ID=1, and John Black is teacher with ID=2?

UPD: Well, it was fixed

  <script>
  $(function() {$( document ).tooltip({ 
    show: 0,
    hide: 0,
    items: 'teacher',
    content: 'connecting',
    content: function(callback) {
            var x=$(this).attr('id') 
            $.get('teacher.php?teacherid='+x,{}, function(data) {
            callback(data);
        });
    },

  })});
  </script> 

And in HTML i now have:

<teacher id="1">Alex Brown</teacher>
<teacher id="2">John Black</teacher>
<teacher id="3">Homer Simpson</teacher>
  • 写回答

4条回答 默认 最新

  • douguadao3883 2014-05-06 06:35
    关注

    First you tag your links with a class

    <div class="teacher-link" data-teacher="1" title="1" onmouseover="{link=1}">Alex Brown</div>
    <div class="teacher-link" data-teacher="2" title="2" onmouseover="{link=2}">John Black</div>
    

    Then hook your tooltips on that class

    $(function() {$( ".teacher-link" ).tooltip({  
        content: 'connecting',
        content:function(callback) {
                var link = $(this).attr("data-teacher"); // here retrieve the id of the teacher 
                $.get('teacher.php?teacherid=' + link,{}, function(data) {
                callback(data);
            });
        },
    
      })});
    

    On non html5 page you can use another attribute like title:

       var link = $(this).attr("title"); // here retrieve the id of the teacher 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?