admin管理员组

文章数量:1317906

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?

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?

Share Improve this question edited Jun 30, 2010 at 11:29 Álvaro González 146k45 gold badges274 silver badges375 bronze badges asked Jun 30, 2010 at 11:10 user370306user370306 1
  • 1 Remember that jQuery is not a synonym for JavaScript. I've added the tag for you. – Álvaro González Commented Jun 30, 2010 at 11:29
Add a comment  | 

2 Answers 2

Reset to default 23

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);​

You can give it a try here

var valuetxtarr = $("#txtarr").val(); 
var valuetxtarrs = valuetxtarr.replace(/\n/g,","); 
alert(valuetxtarrs);

本文标签: javascriptReplace all quotnquot with quotquotStack Overflow