innerText innerHTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
    //弹出消息
        function pop() {
            var a = document.getElementById('a');
            if (a) {
                alert(a.innerText);
                alert(a.innerHTML);
            }
        }
     //修改innerText
        function modifyinnerText() {
            var a = document.getElementById('a');
            a.innerText = "i love u";
//            a.innerHTML = "progra<font color='purple'>mm</font>mmer";
        }

        //修改innerHTML
        function modifyinnerHTML() {
            var a = document.getElementById('a');
//            a.innerText = "i love u";
            a.innerHTML = "progra<font color='purple'>mm</font>mmer";
        }

        //动态创建input标签
        function createInput() {
            var divMain = document.getElementById("divMain");
                       divMain.innerHTML = "<input type='button' value='我是动态标签' />";
//            var input = document.createElement("input");
//            input.type="button";
//            input.value = '动态按钮';
//            divMain.appendChild(input);
        }
    </script>
</head>
<body>
<a id="a" href="http://www.csdn.net">progra<font color='red'>mm</font>mmer</a>
<input type="button" value="inner***" onclick="pop()" />
<input type="button" value="修改innerText" onclick="modifyinnerText()" />
<input type="button" value="修改innerHTML" onclick="modifyinnerHTML()" />
<div id="divMain"></div>
  <input type="button" value="动态创建Input标签" onclick="createInput()" />

</body>
</html>

posted @ 2012-11-25 10:15  FiberHomer  阅读(120)  评论(0编辑  收藏  举报