javascript复习第二天删除元素节点

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
<script> function delList(){ var list = document.getElementsByClassName('list'); var lastlist = list[list.length-1]; lastlist.parentNode.removeChild(lastlist); } </script>
</head>
<body>
    <input type="button" value="删除最后一个元素" onclick = "delList();" />
    <ul>
        <li class = "list">1</li>
        <li class = "list">2</li>
        <li class = "list">3</li>
        <li class = "list">4</li>
    </ul>
</body>
</html>

你可能感兴趣的:(JavaScript)