<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#div1 {
height: 200px;
width: 200px;
background-color: #ccc;
}
</style>
<script>
window.onload = function() {
var oBtn=document.getElementById('btn1');
var oTxt=document.getElementById('txt1');
var oDiv=document.getElementById('div1');
oBtn.onclick = function() {
oDiv.innerHTML=oTxt.value;
}
}
</script>
</head>
<body>
<input id="txt1" type="text">
<input id="btn1" type="button" value="设置文字">
<div id="div1">
</div>
</body>
</html>
不光可以设置里面的文字,真的可以把标签设置进去