[英]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! 非常感谢你!
$(document).ready(function(){})
or $(function(){})
$(document).ready(function(){})
或$(function(){})
$.attr('attribute')
instead of $.attr('attribute').text()
$.attr('attribute')
而不是$.attr('attribute').text()
$.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'
});
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.