如何使用javascript将文本或其他内容写入html文件 [英] How to write text or something to html file using javascript
本文介绍了如何使用javascript将文本或其他内容写入html文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
任何人都可以告诉我如何使用javascript将一些文本写入html文件吗?
在此先感谢
解决方案
有很多方法.您可以编写整个文档等,但是我认为最灵活的方法是修改现有元素的属性.
想法是:您可以通过Id
来获取某个元素,然后为其属性innerHtml
分配一些字符串.
例如:
< html > ; < 头部 > < 标题 > 撰写HTML的依据JavaScript < /title > < 元 =" Content-Type" 内容 =" text/html; charset = utf-8" / < 脚本 =" 文本/javascript" 函数 writeHtml(){ var div = 文档 .getElementById(" 占位符"); div.innerHTML = " ; } -> < / 脚本 > < /head > < 正文 > < 按钮 =" writeHtml();" < < div =" placeholder" / < /body > < /html >
—SA
尝试使用Javascript.
文档 .write(" 您在此处输入文字")
There are a number of methods. You can write whole document, etc., but I think most flexible method is modification of properties of existing elements.
Here is the idea: you get some element by itsId
and then assign some string to its propertyinnerHtml
.
For example:
<html> <head> <title>Writing HTML by JavaScript</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript"><!-- function writeHtml() { var div = document.getElementById("placeholder"); div.innerHTML = "<h2>This is <i><big>generated</big></i> code!</h2>"; } --></script> </head> <body> <button onClick="writeHtml();">Try it!</button> <div id="placeholder" /> </body> </html>
—SA
Try this in Javascript.
document.write("Your text here")
这篇关于如何使用javascript将文本或其他内容写入html文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文