dom元素对象

 

    1、accessKey 属性可设置或返回访问单选按钮的快捷键,简单来说就是为元素添加获取的快捷键    语法:HTMLElementObject.accessKey=accessKey

    2、如果文档树中已经存在了 newchild,它将从文档树中删除,然后重新插入它的新位置。如果 newchild 是 DocumentFragment 节点,则不会直接插入它,
    而是把它的子节点按序插入当前节点的 childNodes[] 数组的末尾。你可以使用 appendChild() 方法移除元素到另外一个元素。    语法:node.appendChild(node)

 

代码:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body οnclick="myfun()">
        <p id="p">按住alt+accesskey(我们自己定义的accesskey)返回文档中当前获得焦点的元素</p>
        <input type="text" value="我的accesskey为i" accesskey="i">
        <button accesskey="b" id="fu">我的accesskey为b</button>
        
        <button οnclick="clister()">点我去除button的监听事件</button>
        <p id="demo"></p>
        <p id="demo1"></p>
        
        <ul id="myList1"><li>小猫1号</li><li>小猫2号</li></ul>
        <ul id="myList2"><li>小狗1号</li><li>小狗2号</li></ul>
        <button οnclick="myfunct()">点我换小动物的位置</button>
        <button οnclick="myfuncti()">点我添加小动物</button>
        
        
        <script>
            //为文本元素添加一个点击函数,让我们很容易知道当前那个文本获得了焦点
            function myfun() {
                var x = document.activeElement.tagName;
                document.getElementById("demo").innerHTML = x;
            }
            //接下来为button元素添加一个监听事件addEventListener,当在button按钮上移动时,随机生成一个0-1的数字
            document.getElementById("fu").addEventListener("mousemove", myfunc);

            function myfunc() {
                document.getElementById("demo1").innerHTML = Math.random();
            };
            //移除监听事件
            function clister() {
                document.getElementById("fu").removeEventListener("mousemove", myfunc);
            };

            function myfunct() {
                var node = document.getElementById("myList2").lastChild;
                document.getElementById("myList1").appendChild(node);
            }

            function myfuncti() {
                var node = document.createElement("LI");
                var textnode = document.createTextNode("小猪1号");
                node.appendChild(textnode);
                document.getElementById("myList1").appendChild(node);
            }
        </script>
    </body>
</html>

 

效果:

好啦,今天的学习到此结束啦!感兴趣的小伙伴可以复制代码看看效果哦

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值