开发者

Javascript, simple: make global

开发者 https://www.devze.com 2023-03-25 10:04 出处:网络
Here is a simple regex expression... document.getElementById(\'testing\').value=f2.innerHTML.replace(\">\",\">\\n\");

Here is a simple regex expression...

document.getElementById('testing').value=f2.innerHTML.replace(">",">\n");

The problem is it stops a开发者_StackOverflow社区fter the first linebreak, how can I make it do the whole table?

Thanks!


Use .replace(/>/g, ">\n");.    

RegEx literal (or at least that's what I call it) uses two /'s. One to mark the begninning, one to mark the end. If you need to use an actual / in the replacement, you'll have to escape the / with a backslash (\). For example: /Hi\/Hello/.

With RegEx literals, modifiers come after the last /. In the case above, "g" means global and will replace all, not just the first one it comes to.

0

精彩评论

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