简体   繁体   English

使用jquery或javascript转义“ <”字符及其中的内容

[英]Escaping “<” character and the contents inside it using jquery or javascript

在此处输入图片说明

The user can select a part of text and can apply styles such as font color, underline etc. The HTML content will be saved in the database in as it was created to maintain the formatting and will be displayed in the client's device as such it was saved. 用户可以选择文本的一部分,并可以应用样式,例如字体颜色,下划线等。HTML内容将在创建时保存在数据库中,以保持格式,并且将原样显示在客户端设备中。已保存。 The problem I'm facing here is that how I can allow contents like shown in the image, <Test> is not an html tag but the browser pretends it is one and hides it from viewing also other texts such as look here >> hello also generates problems. 我在这里面临的问题是我如何允许图像中所示的内容, <Test>不是html标签,但浏览器假装它是其中一个,并且在查看其他文本(例如在此处查看)时也将其隐藏>>你好也产生问题。 Any solution? 有什么办法吗? Here is the client code that will be displayed and by the way I'm using jQuery text editor . 这是将显示的客户端代码,以及使用jQuery文本编辑器的方式。

function NormalPopup(msg,createDate,okMethodName,deleteMethodName,messageId,roomNumber,type,signature, msgStatusFlag){
    msg = replaceMsg(msg);
    document.getElementById('overlay').style.display='block';
    document.getElementById('modal').style.display='block';
    document.getElementById('modal').innerHTML="";
    var divHtml="";
    var buttonName="";
    if(msgStatusFlag=="0" && $("#strong"+messageId).html()!=null)
        buttonName = "Save";
    else
        buttonName = "Close";
    divHtml="<div align='center'><div align='justify' class='divContent'><table align='top' cellspacing='10' cellspacing='10'  width='100%' height='100%'>";
    divHtml=divHtml+"<tr>";
    divHtml=divHtml+"<td align='left' >";
    divHtml=divHtml+"<div id='standard1' class='alertDivTable alertContent'>"+msg+"</div><br>";
    divHtml=divHtml+"</td>";
    divHtml=divHtml+"</tr>";
    divHtml=divHtml+"<tr>";
    divHtml=divHtml+"<tr><td align='left'><div style='text-align:left;'>"+signature+"</div></td></tr>";
    divHtml=divHtml+"<tr>";
    divHtml=divHtml+"<td><table width='100%'><tr><td align='left' width='50%' ><div style='text-align :left;'>"+createDate+"</div></td><td align='right'><div class='alertBoxBtn' align='right'> " +
            "<table width='100%' height='100%' cellpadding='5' cellspacing='8'><tr><td align='center' valign='middle' class='button_td deleteBtn' id='deleteBtn' " +
            "onclick='javascript:closePopup("+deleteMethodName+",\""+messageId+"\",\""+roomNumber+"\",\""+type+"\")'><div>Delete</div></td><td align='center' valign='middle' class='button_td deleteBtn'  " +
            "id='okBtn' onclick='javascript:closePopup("+okMethodName+",\""+messageId+"\",\""+roomNumber+"\",\""+type+"\")' ><div>" +
            buttonName+"</div></td></tr></table></div></td></tr></table></td>";
    divHtml=divHtml+"</tr>";
    divHtml=divHtml+"</div></div></table>";
    document.getElementById('modal').innerHTML =divHtml;

    if(document.getElementById("standard1").scrollHeight>=250){
        document.getElementById("modal").style.top="42%";
        document.getElementById("standard1").style.height='250px';
        document.getElementById("standard1").innerHTML="<div class='scroller' >"+document.getElementById("standard1").innerHTML+"</div>";
        new iScroll('standard1',{ hideScrollbar:false,fixedScrollbar:true,bounce:false });
    }
    else if(document.getElementById("standard1").scrollHeight>=51 && document.getElementById("standard1").scrollHeight<250){
        document.getElementById("modal").style.top="47%";
    }
    else{
        document.getElementById("modal").style.top="52%";
    }
    new NoClickDelay(document.getElementById("deleteBtn"));
    new NoClickDelay(document.getElementById("okBtn"));
}

The message will be displayed using this code 该消息将使用以下代码显示

divHtml=divHtml+"<div id='standard1' class='alertDivTable alertContent'>"+msg+"</div><br>"; 

Have you tried using the backslash character "\\" before the character you are trying to escape? 您是否试图在要转义的字符之前使用反斜杠字符“ \\”? Usually, the backslash is used for escaping characters. 通常,反斜杠用于转义字符。 In this case, that would be "\\" 在这种情况下,该值为“ \\”

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

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