简体   繁体   English

插件工具提示-中继标题

[英]Plugin tooltipster - Trunkate Title

I am using the plugin "tooltipster" but I would like to truncate the title to 30 characters and add hellips. 我正在使用插件“ tooltipster”,但我想将标题截断为30个字符并添加hellips。

I have a list of 3 links. 我有3个链接的列表。 Below is the code and added a link to example 下面是代码,并添加了示例链接

$('.tooltip').tooltipster({
    animation: 'fade',
    delay: 200,
    touchDevices: false,
    trigger: 'hover',
    position: 'bottom',
    theme: 'tooltipster-shadow'
});


$('.box a').each(function(){
    if ($(this).attr('title').text().length > 20) {
        $(this).attr('title').text($(this).text().substr(0, 17)); 
        $(this).attr('title').append(' ...');
    }

});

http://jsfiddle.net/rttUG/ http://jsfiddle.net/rttUG/

thank you very much! 非常感谢你!

  1. You should execute your scripts after the dom is ready, use $(document).ready(function(){}) or $(function(){}) 您应该在dom准备就绪后执行脚本,使用$(document).ready(function(){})$(function(){})
  2. To get attribute value use $.attr('attribute') instead of $.attr('attribute').text() 要获取属性值,请使用$.attr('attribute')而不是$.attr('attribute').text()
  3. To update the attribute value use $.attr('attribute', 'new value') instead of $.attr('attribute').text('new value') 要更新属性值,请使用$.attr('attribute', 'new value')而不是$.attr('attribute').text('new value')

Your new code will be like this: 您的新代码将如下所示:

$(function(){

    $('.box a').each(function(){
        var title = $(this).attr('title');
        if (title.length > 20) {
            $(this).attr('title', title.substr(0, 17) + '...'); 
        }
    })

    $('.tooltip').tooltipster({
        animation: 'fade',
        delay: 200,
        touchDevices: false,
        trigger: 'hover',
        position: 'bottom',
        theme: 'tooltipster-shadow'
    });

})

http://jsfiddle.net/8vpUk/ http://jsfiddle.net/8vpUk/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM