我正在研究jQuery,我需要替换双引号"
。
这就是我的尝试:
var source="flower.jpg","boscket.jpg","cat.jpg";
我想这样做
var newstring=flower.jpg,boscket.jpg,cat.jpg;
我该如何正确地做到这一点?
答案 0 :(得分:2)
你需要这样做:
var source='"flower.jpg","boscket.jpg","cat.jpg"';
var newstring = source.replace(/\"/g,'')
alert(newstring);
我假设来源是包含在''
中的有效字符串答案 1 :(得分:0)
var source="flower.jpg","boscket.jpg","cat.jpg";
会出错n
SyntaxError: missing variable name
你可以这样做
var source='"flower.jpg","boscket.jpg","cat.jpg"';
var newstring = source.replace(/\"/g,'')
答案 2 :(得分:0)
令人遗憾的是
var source="flower.jpg","boscket.jpg","cat.jpg";
无效javascript且无法评估。我假设你有以下字符串:
var source='"flower.jpg","boscket.jpg","cat.jpg"';
要替换所有双引号,请使用以下javascript(不需要jQuery):
source.replace(/"/g, '');
有关string.replace方法的详细信息,请参阅https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/replace。
答案 3 :(得分:0)
Hello Here替换单和双quata的示例
jquery replace all single or double quotes
we can pass two parameter to replace single quotes in string
//replace all single quotes
var myStr = myStr.replace(/'/g, '');
//replace all double quotes
var myStr = myStr.replace(/"/g, '');
//or abit of fun, replace single quotes with double quotes
var myStr = myStr.replace(/'/g, '"');
//or vice versa, replace double quotes with single quotes
var myStr = myStr.replace(/"/g, ''');
jquery replace all single or double quotes
获取参考资料