如何在jquery asp.net mvc中删除撇号? [英] how to escape apostrophe s in jquery asp.net mvc?

查看:72
本文介绍了如何在jquery asp.net mvc中删除撇号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在我的网页上有一个全文搜索,用户输入任何内容并获得结果。现在我在搜索框中有撇号的问题。我的搜索请求用搜索框中的给定文本重写URL,当O'brain或Mark的搜索时,它给出了来自Jquery的错误请求错误。我尝试json.Encode,但不知何故它不起作用。

Hi all,

i have a full text search on my web page where user type anything and get the result. now i have a problem with apostrophe s in search box. my search request rewrite the URL with the given text in search box and when some one search by O'brain or Mark's it gives error of bad request from the Jquery. i try json.Encode but somehow it is not working.

推荐答案

我们可以逃避这些字符,如单引号可以使用反斜杠进行转义。

Ex: -

D'souza可以写成D \'sauza。



如果相同文本正在选择器文本中使用我们可以使用双反斜杠来逃避单引号。



此外,您可以使用正则表达式将字符转义为具有单个或双精度的任何字符串字符为: -



We can escape these kind of characters like single quotes can be escaped using backslashes.
Ex :-
"D'souza" can be written as "D\'sauza".

If the same text is being used in selector text we can use double backslashes to escape the single quote.

Also you can use regular expressions to escape characters to any string having single or double characters as :-

var strReplaced = strToReplace.replace(/(['"])/g, "\\


1 );
1");





希望这会有所帮助。



Hope this will be of help.


这篇关于如何在jquery asp.net mvc中删除撇号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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