document.write的替代品是什么? [英] What are alternatives to document.write?

查看:211
本文介绍了document.write的替代品是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在教程中,我学会了使用 document.write 。现在我明白很多人对此不以为然。我已经尝试了 print(),但它确实将它发送到打印机。

In tutorials I've learnt to use document.write. Now I understand that by many this is frowned upon. I've tried print(), but then it literally sends it to the printer.

那么什么是替代品我应该使用,为什么我不应该使用 document.write ? w3schools和MDN都使用 document.write

So what are alternatives I should use, and why shouldn't I use document.write? Both w3schools and MDN use document.write.

推荐答案

作为推荐替代 document.write 您可以使用 DOM操作直接查询并向DOM添加节点元素。

As a recommended alternative to document.write you could use DOM manipulation to directly query and add node elements to the DOM.

这篇关于document.write的替代品是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆