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条)

报告相同问题?

悬赏问题

  • ¥15 用三极管设计—个共射极放大电路
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示