为了账号安全,请及时绑定邮箱和手机立即绑定

cloneNode报错

cloneNode报错

慕先生4463397 2017-05-03 20:28:28
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="description" content=""><meta name="keywords" content=""><title>Examples</title><style type="text/css">    *{margin: 0;padding: 0;}    a{text-decoration: none;color: #333;}    ul,li{list-style: none;}    body{font-size: 14px;font-family: "微软雅黑";}</style></head><body><div id="box">    112444    <span>22</span></div>    <script type="text/javascript">    var box = document.getElementById("box");    fn(box.nextSibling.nodeName);//nextSibling返回此对象往后的紧跟节点,以对象方式返回;nodeName返回节点名称    var copy=document.getElementById("box").lastChild.cloneNode("aaa");    document.getElementsByTagName("span").appendChild(copy);    function fn(value){        return document.write(value+'\n');    }    </script></body></html>实在找不到这26行哪里错了
查看完整描述

1 回答

已采纳
?
西兰花伟大炮

TA贡献376条经验 获得超318个赞

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="">
<meta name="keywords" content="">
<title>Examples</title>
<style type="text/css">
    *{margin: 0;padding: 0;}
    a{text-decoration: none;color: #333;}
    ul,li{list-style: none;}
    body{font-size: 14px;font-family: "微软雅黑";}
</style>
</head>
<body>
<div id="box">
    112444
    <span>22</span>
</div>
    <script type="text/javascript">
    var box = document.getElementById("box");

    fn(box.nextSibling.nodeName);//nextSibling返回此对象往后的紧跟节点,以对象方式返回;nodeName返回节点名称
    var copy=document.getElementById("box").lastChild.cloneNode("aaa");

    document.getElementsByTagName("span")[0].appendChild(copy);



    function fn(value){
        return document.write(value+'\n');
    }
    </script>
</body>
</html>

因为返回的html集合,要用索引取,26行加上索引,就没错了,但是不知道你代码想干嘛

查看完整回答
1 反对 回复 2017-05-03
  • 1 回答
  • 0 关注
  • 1474 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信