innerHTML的用法

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style type="text/css">
    #div1 {width: 200px;height: 200px;border: 1px solid black;}
</style>
</head>

<body>
<input id="txt1" type="text">
<input id="put1" type="button" value="改文字" />
<br/><br/>
<div id="div1"></div>
<script>
    var otxt=document.getElementById('txt1');
    var oput=document.getElementById('put1');
    var odiv=document.getElementById('div1');
    oput.onclick=function()
    {
        odiv.innerHTML=otxt.value;/*innerHTML里面就是正常的HTML,可以放上p、h1等*/
    }
</script>
</body>
</html>

 

posted @ 2018-01-06 16:01  绿林豪士  阅读(294)  评论(0编辑  收藏  举报