简体   繁体   English

将document.write字符串放入元素

[英]Place document.write string in element

Im using 我正在使用

document.write("Your IP is :", userip)

To output IP that I targets for a specific use - I need to hide this string in the dom. 要输出我针对特定用途的IP-我需要将此字符串隐藏在dom中。 I tried this and It shows in a span in the dom but not fully working: 我尝试了这个,它在dom的跨度中显示,但是没有完全正常工作:

document.write("<span>\Your IP is :\, userip</span>");

If I tried to add a class to it it didn't work at all. 如果我尝试向其中添加一个类,那么它根本不起作用。

How Do I hide it, but keeping it in the DOM? 如何隐藏它,但将其保留在DOM中?

You could do this as follows: 您可以按照以下步骤进行操作:

document.write('<span style="display:none">Your IP is :' + userip + '</span>');

But consider not using document.write at all, and using DOM methods to insert content once the document is loaded. 但是请考虑完全不使用document.write ,并且在文档加载后使用DOM方法插入内容。

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

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