【发布时间】:2016-09-30 20:48:22
【问题描述】:
我的页面有两个文本区域和一个 div。一个textarea供用户输入html,另一个用于输入css。单击按钮时,我将调用 javascript 函数来显示 div 中的 css 和 html。
function handleLaunch() {
var div = document.getElementById('pane');
var html = document.getElementById('h');
var css = document.getElementById('c');
div.innerHTML = html.value;
// This line obviously doesn't work div.style = css.value;
}
<body>
<textarea id="c" placeholder="CSS code here..." rows="10" cols="50"></textarea>
<div id="pane">
</div>
<br>
<textarea id="h" placeholder="Html code here..." rows="10" cols="50"></textarea>
<br>
<button type="button" onclick="handleLaunch()">Launch</button>
现在,如何将 css 设置为文本?
编辑:我应该提到我希望能够放置类似的东西 .classExample{text-align:center} 在 css textarea 中并应用它。
【问题讨论】:
-
无论如何
div.style.cssText = css.value会让你在输入中输入 CSS -
很遗憾没有成功
-
你确定 div.style.cssText = "background-color: red"; 不起作用?
-
设置一个能够添加多行的 3 列输入不是更有意义吗?因此,您将拥有 ID、类和 CSS,然后您可以根据需要添加或删除行,这样您就可以定位特定的 ID 或类名。
-
我不太清楚你的意思。你能给我一个编码的例子吗?
标签: javascript html css