Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在firefox上截断长字符串_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 如何在firefox上截断长字符串

Javascript 如何在firefox上截断长字符串,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我想让文本在下面显示两行图像。 这就是它在chrome上的样子,但在firefox上却不起作用。我发现这个网站有chrome教程。链接:。使用-webkit线夹检查我们要添加的线。。。。然而,在firefox上,我们没有像本教程那样的标签webkit线夹。所以有任何方法可以在firefox上截断文本。我使用了如下javascript来修剪字符串 String.prototype.truncString = function(max, add){ add = add || '...';

我想让文本在下面显示两行图像。

这就是它在chrome上的样子,但在firefox上却不起作用。我发现这个网站有chrome教程。链接:。使用-webkit线夹检查我们要添加的线。。。。然而,在firefox上,我们没有像本教程那样的标签webkit线夹。所以有任何方法可以在firefox上截断文本。我使用了如下javascript来修剪字符串

String.prototype.truncString = function(max, add){
    add = add || '...';
    return (this.length > max ? this.substring(0,max)+add : this);
};
if($(".smaller_768 ").width() < 200 && $(".smaller_768 ") > 120){
    trim_content(28);
}
function trim_content(numberofwords){
            $(".smaller_768").each(function(){
                var content = $.trim($(this).text());
                $(this).text(content.truncString(numberofwords, "..."));
            });
}
但是当我改变设备时,它不能很好地工作,因为div的大小改变了


提前感谢。

尝试使用以下方法调用窗口调整功能:

$(window).on("resize", function(){
   if($(".smaller_768 ").width() < 200 && $(".smaller_768 ") > 120){
      trim_content(28);
   }
});

使用resize(调整大小)功能,每次调整浏览器大小时,它都会更改字符串的数量

您所指的站点有多种方法可以实现此目的;其中,代码笔中的两个JS解决方案似乎可以处理文本被禁用区域的大小调整,非常好…