【问题标题】:How to html encode in jquery so that '&' dosent appear如何在 jquery 中进行 html 编码,以便不出现“或”
【发布时间】:2013-06-24 10:22:34
【问题描述】:

在 jquery 中搜索编码文本给了我这个功能

function htmlEncode(value) {
//create a in-memory div, set it's inner text(which jQuery automatically encodes)
//then grab the encoded contents back out.  The div never exists on the page.
return $('<div/>').text(value).html();
}

这运行正常。但是我将此值作为查询字符串传递,并且当有“&”符号时,它只会被“&amp”替换,当我尝试通过 C#(服务器端)获取查询字符串时,& 之后的所有文本都会丢失。

注意:我在客户端创建查询字符串,但在服务器(IIS)上需要它 我怎样才能缓解这个问题。提前谢谢。

【问题讨论】:

    标签: jquery asp.net query-string


    【解决方案1】:

    试试看

    return $('div').html(value).text();
    

    &lt;div/&gt; 是什么,我想应该是 div

    【讨论】:

    • 我需要通过服务器端c#而不是客户端获取它
    猜你喜欢
    • 2017-11-15
    • 1970-01-01
    • 1970-01-01
    • 2010-09-19
    • 1970-01-01
    • 2012-10-15
    • 2011-10-24
    • 2017-05-12
    • 2023-04-05
    相关资源
    最近更新 更多