admin管理员组文章数量:1290267
I m trying to replace some values from a date but it only change the first found value.
var date= cars.getAttribute("myLastDate");
var dateChanged= date.replace("/", ",");
alert (dateChanged);
Best regards.
I m trying to replace some values from a date but it only change the first found value.
var date= cars.getAttribute("myLastDate");
var dateChanged= date.replace("/", ",");
alert (dateChanged);
Best regards.
Share Improve this question asked Nov 27, 2012 at 10:52 Fran RodFran Rod 5964 gold badges14 silver badges26 bronze badges 2- can you put your html code part? – polin Commented Nov 27, 2012 at 10:53
-
MDN is a really good reference on usage of JS functions like
.replace()
, and on JS in general. – nnnnnn Commented Nov 27, 2012 at 10:56
3 Answers
Reset to default 4If you don't need any regular expressions then I remend the simpler split/join method to do search and replace.
var dateChanged = date.split("/").join(",");
You need to invoke the global flag using a regular expression:
var dateChanged= date.replace(/\//g, ",");
replace in javascript use regular expression , u have to add /g at the end
date.replace(text/g,' ')
本文标签: javascriptdate and replace method only change the first found valueStack Overflow
版权声明:本文标题:javascript - date and replace method only change the first found value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741441421a2378941.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论