jQuery 如何使用jquery将所有双引号替换为单引号?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8207297/
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-27 10:12:11  来源:igfitidea点击:

How to replace all double quotes to single quotes using jquery?

jquerystringreplace

提问by DEVOPS

I need to replace all double quotes to single quotes using jquery.

我需要使用 jquery 将所有双引号替换为单引号。

How I will do that.

我将如何做到这一点。

I tested with this code but its not working properly.

我使用此代码进行了测试,但无法正常工作。

newTemp = newTemp.mystring.replace(/"/g, "'");

newTemp = newTemp.mystring.replace(/"/g, "'");

回答by amit_g

Use double quote to enclose the quote or escape it.

使用双引号将引号括起来或将其转义。

newTemp = mystring.replace(/"/g, "'");

or

或者

newTemp = mystring.replace(/"/g, '\'');