English 中文(简体)
在POST前采用超文本
原标题:Encode HTML before POST

我有以下文字,其中含有它适当获得的某些价值,但似乎并没有形成双重引用。

在张贴之前,我如何妥善确定全部价值?

function htmlEncode(value){ 
    return $( <div/> ).text(value).html(); 
} 

上述文字给我:

&lt;p&gt;Test&amp;nbsp; &lt;span style="color: #ffffff"&gt;&lt;strong&gt;&lt;span style="background-color: #ff0000"&gt;1+1+1=3&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;

我需要我:

&lt;p&gt;Test&amp;nbsp; &lt;span style=&quot;color: #ffffff&quot;&gt;&lt;strong&gt;&lt;span style=&quot;background-color: #ff0000&quot;&gt;1+1+1=3&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;

EDIT: Followup question: Encoded HTML in database back to page

最佳回答

你们不要试图把东西与 Java联系起来。

您应将其服务器编码。

与贾瓦特文做的任何事情都是不可否认的。

如果你也检查在服务器上编码,但铭记:Java 字典可以残疾,则将其编码在 Java本中是有效的。

问题回答

What George says is true. But, if you have to encode strings client-side, I d suggest you use JavaScript s encodeURIComponent().

客户方面的使用越狱

以及

缩略语

它为我工作。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!