如何逃脱"&安培;"使用jQuery的形式输入符号字符 [英] How to escape "&" ampersand character in form input using jQuery

查看:147
本文介绍了如何逃脱"&安培;"使用jQuery的形式输入符号字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,它通过POST方法发送数据,我的jQuery脚本。现在的问题是每当它通过Ajax具有一个发送数据与&符号中的一句话,就会发现时削减了一句&放大器;

I have a problem with my jQuery script that send data via POST method. The problem is whenever it sends data via Ajax that has an "&" ampersand in the sentence, it will cut the sentence when found "&".

请检查下面的图片了解更多信息。

Please check the images below for more info.

推荐答案

htmlentites

这个功能是相同的用htmlspecialchars ()在各方面,除了与的htmlentites (),其中有HTML字符实体等同的所有字符被转换为这些实体。

This function is identical to htmlspecialchars() in all ways, except with htmlentites(), all characters which have HTML character entity equivalents are translated into these entities.

如果你想取消code,而不是(反向),可以使用的 html_entity_de code ()。

If you're wanting to decode instead (the reverse) you can use html_entity_decode().

例如:

echo htmlentities("&"); // &

如果你直接这样做,在浏览器中,你应该能够使用:

if your directly doing this in the browser you should be able to use:

encodeURIComponent(string input);

例如:

encodeURIComponent($.trim($("input[name=t-tim_rendered-"+id+"]").val().toString()));

这篇关于如何逃脱"&安培;"使用jQuery的形式输入符号字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆