简体   繁体   English

在此JS代码中启用HTML标签

[英]Enabling HTML tags in this JS Code

I use this code for creating Summary of the Blog Posts at my blog Gadgetcage.com, In this JS code HTML tags are disabled by the author, I would like to remove that disabling HTML tag function in this Code. 我使用此代码在我的博客Gadgetcage.com上创建博客文章摘要,在此JS代码中,HTML标记已被作者禁用,我想在此代码中删除禁用HTML标记功能。 Please help me!! 请帮我!!

function removeHtmlTag(strx,chop){ 
    if(strx.indexOf("<")!=-1)
    {
        var s = strx.split("<"); 
        for(var i=0;i<s.length;i++){ 
            if(s[i].indexOf(">")!=-1){ 
                s[i] = s[i].substring(s[i].indexOf(">")+1,s[i].length); 
            } 
        } 
        strx =  s.join(""); 
    }
    chop = (chop < strx.length-1) ? chop : strx.length-2; 
    while(strx.charAt(chop-1)!=' ' && strx.indexOf(' ',chop)!=-1) chop++; 
    strx = strx.substring(0,chop-1); 
    return strx+'...'; 
}

function createSummaryAndThumb(pID){
    var div = document.getElementById(pID);
    var imgtag = "";
    var img = div.getElementsByTagName("img");
    var summ = summary_noimg;
    if(img.length>=1) { 
        imgtag = '<span style="float:left; padding:0px 10px 5px 0px;"><img src="'+img[0].src+'" width="'+img_thumb_width+'px" height="'+img_thumb_height+'px"/></span>';
        summ = summary_img;
    }

    var summary = imgtag + '<div>' + removeHtmlTag(div.innerHTML,summ) + '</div>';
    div.innerHTML = summary;
}

您只需要避免调用以下函数:removeHtmlTag(div.innerHTML,summ)。

If you want to allow html, just create a new function consisting of 如果要允许html,只需创建一个新函数,其中包括

function truncateSummary(strx, chop) {
  chop = (chop < strx.length-1) ? chop : strx.length-2; 
  while(strx.charAt(chop-1)!=' ' && strx.indexOf(' ',chop)!=-1) chop++; 
  strx = strx.substring(0,chop-1); 
  return strx+'...'; 
}

and change the var summary line to 并将var摘要行更改为

var summary = imgtag + '<div>' + truncateSummary(div.innerHTML,summ) + '</div>';

I'm don't know too much about JavaScript, but shouldn't this do the trick. 我对JavaScript不太了解,但是不应该这样做。

function createSummaryAndThumb(pID){
    var div = document.getElementById(pID);
    var imgtag = "";
    var img = div.getElementsByTagName("img");
    if(img.length>=1) { 
        imgtag = '<span style="float:left; padding:0px 10px 5px 0px;"><img src="'+img[0].src+'" width="'+img_thumb_width+'px" height="'+img_thumb_height+'px"/></span>';
    }

    var summary = imgtag + '<div>' + div.innerHTML + "..." + '</div>';
    div.innerHTML = summary;
}

Just use that and delete the removeHtmlTag function 只需使用它并删除removeHtmlTag函数

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

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