我试图创造一些像JavaScript的一个小编辑器,但我不明白为什么.style不工作..风格CSS不提前工作
感谢帮帮我!
这是我的代码:
<html>
<head>
<title>Hello World!</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
<body>
<div>
<textarea cols="30" rows="1" id="title1">write here the header</textarea><br /><br />
<textarea cols="30" rows="1" id="desc1">write here the paragraph</textarea>
<input type="button" value="show" onclick="doit()">
</div>
<script type="text/javascript">
function doit() {
var title = document.getElementById("title1").value;
var desc = document.getElementById("desc1").value;
document.write("<h1>"+title+"</h1>").style.color="blue";
document.write(desc);
}
</script>
</body>
</html>
'document.write'是不是一个好主意使用'append'代替 – Ani
文件撰写不返回一个DOM元素。 –
为什么不使用jQuery? – Waclock