开发者

Replace every tab (key) with string in jQuery?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜