Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.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 jQuery中截断html内容的问题_Javascript_Jquery - Fatal编程技术网

Javascript jQuery中截断html内容的问题

Javascript jQuery中截断html内容的问题,javascript,jquery,Javascript,Jquery,这是我的截断函数: function truncate_updates(txt, cnt, opt) { if(updates_topic=='') { return truncateText(txt, cnt, opt); } else { return txt; } } function truncateText(text, len, show_readmore) { if(te

这是我的截断函数:

function truncate_updates(txt, cnt, opt) {
        if(updates_topic=='') {
            return truncateText(txt, cnt, opt);
        } else {
            return txt;
        }
    }

function truncateText(text, len, show_readmore) {
    if(text==''|| text==null)
        return;
    if(text.length > len) {
        if(show_readmore == 'truncate')
            text = text.substring(0, len)+'...';
        else if(show_readmore=='link')
            text = text.substring(0, len)+'<span class="cpoint circuitCol"> more</span>';
        else if(show_readmore != false)
            text = '<span act="show_trn_txt">'+text.substring(0, len)+'</span><span class="cpoint circuitCol" act="show_readmore_text"> read more</span><span act="readmore" class="display-hide">'+text+'</span>';
    }
    return text;
}
函数截断_更新(txt、cnt、opt){
如果(更新主题==''){
返回truncateText(txt、cnt、opt);
}否则{
返回txt;
}
}
函数truncateText(text、len、show\u readmore){
如果(文本=''| |文本==null)
返回;
如果(text.length>len){
if(show_readmore=='truncate')
text=text.substring(0,len)+'…';
else if(show_readmore=='link')
text=text.substring(0,len)+“more”;
else if(show_readmore!=false)
text=''+text.substring(0,len)+'readmore'+text+'';
}
返回文本;
}
当我尝试使用此函数截断时,HTML内容会中断

HTML内容:

<a class="ashcol">dsdsdsad sdasdasd dsdasd asdasdsa sdasdasdasd sdasdasdasd sdsadasdasd sdasdasdasd sdasdasdasd sdasdsd dssds sdsds sdsds sdsd sdsdsd sdsdsd sdsd </a><a href="http://192.168.1.41/4thambit_v6/hashtags/hashtag=fourthambit">#fourthambit</a> <a href="http://192.168.1.41/4thambit_v6/hashtags/hashtag=socialmedia">#socialmedia</a> <a href="http://192.168.1.41/4thambit_v6/hashtags/hashtag=development">#development</a> <a href="http://192.168.1.41/4thambit_v6/hashtags/hashtag=cakephp">#cakephp</a> <a href="http://192.168.1.41/4thambit_v6/hashtags/hashtag=php">#php</a>


您介意使用css
文本省略号吗。这里的解决方案len是否考虑了您添加的文本的长度,以显示有更多的内容?(“…”,“more”)@MuhaiminAbdul-tat不会这样做,因为我有多行代码…我是用php做的。。。任何寻找php方式的人都可以点击这个链接