简体   繁体   English

ReplaceAll() 在移动 JavaScript 中不起作用

[英]ReplaceAll() not working in mobile JavaScript

In my following code I am trying to show the table code in textarea when page loads.在我下面的代码中,我试图在页面加载时在 textarea 中显示表格代码。 My code is properly working in desktop device but when I am trying this in mobile phone the code not showing in textarea.我的代码在桌面设备上正常工作,但是当我在手机中尝试这个时,代码没有显示在 textarea 中。 I tried removing replaceAll then it's working in mobile as well.我尝试删除 replaceAll 然后它也可以在移动设备上运行。 I don't understand why it's happening please help!我不明白为什么会这样,请帮忙!

Code:代码:

 function myFunction() { var elem = document.getElementById("myTable"); document.getElementById("showTableCode").value=elem.outerHTML.replaceAll("<tbody>", '').replaceAll("</tbody>", '').replace(/(\\r\\n|\\r|\\n){2,}/g, '\\n'); }
 table, th, td{ border: 1px solid black; border-collapse: collapse; } th, td { padding: 15px; text-align: left; }
 <body onload="myFunction()"> <center> <table id="myTable"> <tr><th><b>Fruit</b></th><th><b>Veg</b></th></tr> <tr><td>Apple</td><td>Tomato</td></tr> <tr><td>Banana</td><td>Potato</td></tr> <tr><td>Mango</td><td>Online</td></tr> </table></center><br> <textarea cols="30" style="width: 100%;" id="showTableCode" rows="10"> </textarea>

You can try using您可以尝试使用

 a = a.replace(/<tbody>/g,"");

I am assuming everything in a , then you can apply this and no need of using of replaceAll()我假设所有内容都在a ,然后您可以应用它而无需使用replaceAll()

Refer to this for more details String.prototype.replace()有关详细信息,请参阅此String.prototype.replace()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM