dougan1330 2013-07-23 06:32
浏览 216
已采纳

如何使用工具提示限制要显示的名称长度和显示全名

if I have to echo a long name out

echo "arnold schwarzenegger";

I want it to limit the word length and display the first 6 char, and display the rest in "..."

arnold...

How to do it? and is there a way for to display the long name when I hover my cursor over the "..."?

  • 写回答

5条回答 默认 最新

  • duanpang2751 2013-07-23 07:20
    关注

    You are essentially asking two different questions here.

    Shortening the name

    This has been answered a couple of times already, but the most easy syntax would be:

    strlen($name, 0, 10);
    

    This only shows the first 10 characters. The "0" stands for the start.

    I'm hoping you're using objects for this, as you can easily add a method to your model and use something like:

    $user->getShortname();
    

    This would make doing the second part a lot easier as well.

    Showing the tooltip with the full name

    Depending on your structure and architecture; you can easily have the original full name and the shortened name living together in the same object or in different variables.

    Depending on your choice of tools (jQuery, any additional plugins you want to use, etc.), you can easily add a tooltip plugin. jQuery-UI has a nice one if I may suggest one.

    Adding it depends on your choice of tools, it varies how difficult it would be to add a tooltip. With the jQuery-UI version it's as easy as:

    <span class="tooltip" title="<?=$user->getFullname()?>"><?=$user->getShortname()?></span>
    

    And add the following Javascript to your page:

    $(".tooltip").tooltip();
    

    That should work just fine :-). If you have any more specific questions for one of these parts; either update your original post or create a new question.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题