替换所有“\n"与“," [英] Replace all "\n" with ","
本文介绍了替换所有“\n"与“,"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 textarea,我想用,"替换它的值中的\n".
I have a textarea and I want to replace "\n" with "," in it's value.
var valuetxtarr = $("#txtarr").val();
var valuetxtarrs = valuetxtarr.replace("/\n/g",",");
alert(valuetxtarrs);
但它不起作用?为什么?我哪里出错了?
But it don't work?Why?Where I have mistake?
推荐答案
你只需要去掉引号(否则它正在寻找那个字符串),像这样:
You just need to remove the quotes (otherwise it's looking for that string), like this:
var valuetxtarr = $("#txtarr").val();
var valuetxtarrs = valuetxtarr.replace(/\n/g,",");
alert(valuetxtarrs);
这篇关于替换所有“\n"与“,"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文