【发布时间】:2018-10-03 06:35:05
【问题描述】:
如何使用 Javascript 创建基本的 HTML/CSS 编辑器?我有下面的代码,当我按下按钮时,HTML 和 CSS 部分的代码应该在元素中显示格式。
<html>
<head>
<style>
textarea {
width: 45%;
height: 200px;
background: #eee;
margin: 0 2%;
}
#content {
margin: 0 20px;
border: 1px solid #aaa;
min-height: 200px
}
h1 {
text-align: center;
font-size: 20px
}
h2 {
font-size: 18px
}
</style>
</head>
<body>
<h1>A basic HTML / CSS editor</h1>
<textarea id="html-code" placeholder="Insert HTML here"></textarea>
<textarea id="css-code" placeholder="Insert CSS here"></textarea>
<button onclick="editor()">Apply HTML and CSS</button>
<h2>Result</h2>
<div id="content">
</div>
</body>
</html>
【问题讨论】:
-
您是否希望将代码保存到您的计算机并进行更新?还是您希望它在浏览器中运行?喜欢 SO 代码 sn-ps?
-
在浏览器中。
-
那么我唯一能想到的就是将它链接到节点服务器,以便您可以覆盖文件
标签: javascript