开发者

Replace every tab (key) with string in jQuery?

开发者 https://www.devze.com 2022-12-26 23:06 出处:网络
I need to go though a content of element, and replace every tabulator \\t w开发者_开发技巧ith text \"(Here\'s a tab)\". How is this possible?

I need to go though a content of element, and replace every tabulator \t w开发者_开发技巧ith text "(Here's a tab)". How is this possible?

Martti Laine


You can use the replace() method on a string:

var el = $('#myEl').text();
el.replace(/\t/g, "(Here's a tab)");

Note: you must use a regular expression with the /g modifier to replace every instance of \t, using a string for the search will only replace the first occurrence.

0

精彩评论

暂无评论...
验证码 换一张
取 消