Javascript 如何通过 jQuery 删除值中的反斜杠?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6758734/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 23:04:23  来源:igfitidea点击:

how can remove backslash in value by jQuery?

javascriptjqueryjavascript-eventsjquery-validate

提问by Mehd S

if$(this).val() have backslash remove backslash in it by jQuery. how is it? 1111\/11\/11-> 1111/11/11

如果$(this).val() 有反斜杠,则通过 jQuery 删除其中的反斜杠。如何? 1111\/11\/11->1111/11/11

回答by Mark Keats

$(this).val().replace(/\/g, '');

You have to use two backslashes to get the \ character. A single backslash is used for control characters such as \r \n etc. Using the double backslash escapes this and gives you what you want.

您必须使用两个反斜杠来获取 \ 字符。单个反斜杠用于控制字符,例如 \r\n 等。使用双反斜杠可以转义这一点,并为您提供所需的内容。

回答by kleinohad

var str = $(this).val().replace('/','');

回答by naveen

Try this.

尝试这个。

$(this).val($(this).val().replace(/\/gi, ""));