我有这个字符串:
"Test abc test test abc test test test abc test test abc"
Run Code Online (Sandbox Code Playgroud)
干
str = str.replace('abc', '');
Run Code Online (Sandbox Code Playgroud)
似乎只删除abc上面字符串中的第一次出现.如何更换所有出现的内容?
从字符串中删除数字
questionText = "1 ding ?"
Run Code Online (Sandbox Code Playgroud)
我想替换这个号码和问题号码,号码可以是任意号码,我尝试下面的代码不起作用
questionText.replace(/[0-9]/g, '');
Run Code Online (Sandbox Code Playgroud) var variableABC = "A B C";
variableABC.replace('B', 'D') //wanted output: 'A D C'
Run Code Online (Sandbox Code Playgroud)
但'variableABC'没有改变:
variableABC ='ABC'
当我希望它是'AD C'时.
我找不到解决方案,用点替换.
var tt="88,9827";
tt.replace(/,/g, '.')
alert(tt)
//88,9827
Run Code Online (Sandbox Code Playgroud)
我正在尝试将逗号替换为点
提前致谢
尝试用变量替换字符串中#的所有实例.它没有工作,但也没有重新调整任何错误.
answer_form = '<textarea name="answer_#" rows="5"></textarea>'+
'<input type="file" name="img_#" />';
question_num = 5;
answer_form.replace(/#/g, question_num);
Run Code Online (Sandbox Code Playgroud)
哈希仍然存在.
不确定我错过了什么?
function areaMe(area) {
var barea = $('#barea').val();
if (barea.indexOf(area) != -1) {
alert ("..." + barea + "..." + area + "...");
barea.replace(area, "cu"); // Remove
alert ("..." + barea + "..." + area + "...");
}
else {
barea += area + ' '; // Include.
}
$('#barea').val(barea);
}
Run Code Online (Sandbox Code Playgroud) 我按照一些文档来使用JavaScript替换功能,并没有改变任何东西.没有错误被抛出.知道我做错了什么吗?该变量是从XML中检索的 - 可能需要将其转换为字符串或其他内容?
for (var i = 0, iln = projects.length; i < iln; i++){
var thumb = projects[i].get('thumb');
thumb.replace("200.jpg", "640.jpg");
console.log(thumb) //200.jpg not replaced
}
Run Code Online (Sandbox Code Playgroud)
完整的拇指值应如下所示:
http://b.vimeocdn.com/ts/160/895/160895498_200.jpg
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来寻找和替换东西?
这似乎是如此简单和微不足道,但它无法正常工作.这是我的javascript:
var url = "/computers/";
console.log(url);
url.replace(/\//gi, " ");
console.log(url);
Run Code Online (Sandbox Code Playgroud)
这是我的浏览器控制台中的输出:
/computers/
/computers/
Run Code Online (Sandbox Code Playgroud)
你可以看到没有任何变化.你可以从代码中看出我试图用空格替换正斜杠.我究竟做错了什么?
我有一个我想要操作的简单字符串:
您的订单将很快得到处理:
我用以下方法抓住字符串:
var html = jQuery('.checkout td h4').html();
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用以下命令替换':':
html.replace(":", ".");
Run Code Online (Sandbox Code Playgroud)
当我将其打印到控制台时,该字符串与原始字符串相同.我还尝试html通过执行以下操作确保变量的类型为"string":
html = html + "";
Run Code Online (Sandbox Code Playgroud)
这没有任何作用.在搜索时,似乎该replace函数执行RegEx搜索并且":"字符可能具有特殊含义.我不知道如何解决这个问题.有人可以帮助我摆脱这个臭的冒号吗?
我在网站上搜索了一下,但它仍然没有用.
var blah2 = JSON.stringify({foo: 123, bar: <x><y></y></x>, baz: 123});
Run Code Online (Sandbox Code Playgroud)
这是我试过的:
blah2.replace(/[{}]/g, "");
Run Code Online (Sandbox Code Playgroud)
这就是字符串出来的地方:
got "{\"baz\":123,\"foo\":123}"
Run Code Online (Sandbox Code Playgroud)
(我知道这可能是一个新问题,但这是我第一次使用javascript,我只是不知道我错过了什么)