我正在使用
document.write("Your IP is :", userip)
要输出我针对特定用途的 IP - 我需要在 dom 中隐藏此字符串。我尝试了这个,它显示在 dom 中的一个跨度中,但没有完全工作:
document.write("<span>\Your IP is :\, userip</span>");
如果我尝试向其中添加一个类,它根本不起作用。
如何隐藏它,但将其保留在 DOM 中?
最佳答案
您可以按如下方式执行此操作:
document.write('<span style="display:none">Your IP is :' + userip + '</span>');
但请考虑not using document.write
完全可以,并在文档加载后使用 DOM 方法插入内容。
关于javascript - 将 document.write 字符串放入元素中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40655168/