简体   繁体   中英

ReplaceAll() not working in mobile JavaScript

In my following code I am trying to show the table code in textarea when page loads. My code is properly working in desktop device but when I am trying this in mobile phone the code not showing in textarea. I tried removing replaceAll then it's working in mobile as well. 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()

Refer to this for more details String.prototype.replace()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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