<!DOCTYPE html><html><head> <title>DOM常用操作</title> <meta charset="utf-8"></head><body> <div id="users"> <h2>8882人在学习该课程:</h2> <ul> <li class="user"> <img src="1.jpg"> <a href="/user/1">Satoshi</a> </li> <li class="user"> <img src="2.jpg"> <a href="/user/2">春来草青</a> </li> <li class="user last"> <img src="3.jpg"> <a href="/user/3">Kash</a> </li> </ul> </div> <script> var users = document.getElementById("users"); var ul = users.getElementsByTagName("ul")[0]; var li = document.creatElemtent("li"); li.className = "user"; ul.appendChild(li); //无双引号 var img = document.creatElemtent("img"); img.src = "4.jpg"; li.appendChild(img); var a = document.creatElemtent("a"); a.innerText = "lifeng"; a.href="/user/4"; li.appendChild(a);</script></body></html>
添加回答
举报
0/150
提交
取消