dongyihang3575 2014-05-23 01:57
浏览 65
已采纳

单词修剪工具提示jquery

Basically I want my tooltip to display company names once company_id is being hovered. However instead of displaying "Company A" for example, it just displays "Company". I realized that it's just printing everything before a space.

Here's the script:

<script type="text/javascript">
  $(document).ready(function() {
  // Tooltip only Text
  $('.masterTooltip').hover(function(){
    // Hover over code
    var title = $(this).attr('title');
    $(this).data('tipText', title).removeAttr('title');
    $('<p class="tooltip"></p>')
    .text(title)
    .appendTo('body')
    .fadeIn('slow');
}, function() {
    // Hover out code
    $(this).attr('title', $(this).data('tipText'));
    $('.tooltip').remove();
 }).mousemove(function(e) {
    var mousex = e.pageX + 20; //Get X coordinates
    var mousey = e.pageY + 10; //Get Y coordinates
    $('.tooltip')
    .css({ top: mousey, left: mousex })
 });
});
</script>

and here's my codes

<?php
  $companyCtrl = new company_controller();
  $companyInfoArr = $companyCtrl->retrieveAllCompanyInfo();
  foreach($companyInfoArr as $info) {
    $company_id = $info->getCompanyID();
    $company_name = $info->getCompanyName();
    echo "<a href='#' title=".$company_name." class='masterTooltip'>".$company_id."</a> <br>";
  }
?>

There's not problem when i manually enter the text like this

<a href="#" title="This will show up in the tooltip" class="masterTooltip">Your Text</a>
  • 写回答

1条回答 默认 最新

  • dongyunque2511 2014-05-23 02:36
    关注

    In this line:

    echo "<a href='#' title=".$company_name." class='masterTooltip'>".$company_id."</a> <br>";
    

    You need to add quotes around the title, so the HTML you're generating will be properly formed. Like this:

    echo "<a href=\"#\" title=\"".$company_name."\" class=\"masterTooltip\">".$company_id."</a> <br>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程