zoukankan      html  css  js  c++  java
  • js点击事件,添加或删除元素,定时器

    // 点击事件
        document.getElementById('dj').onclick = function(){
            alert('点击')
        }
        // 失去焦点
        document.getElementById('inp').onblur = function(){
        console.log('失去焦点');
        }
        // 获取焦点
        document.getElementById('inp').onfocus = function(){
        console.log('获取焦点');
        }
        // 添加新元素
        // var p = document.createElement('p'); //创建一个新元素
        // var nod = document.createTextNode('新段落');//创建一个新文本节点
        // p.appendChild(nod);//拼接起来
        // document.getElementById('dj').appendChild(p); //添加到元素中
        
        // document.getElementById('but').onclick = function(){

         //删除元素
        // var parent  = document.getElementById('dj'); //找到父级div
        // var child  = document.getElementById('dl');//找到元素
        // parent.removeChild(child);

        //替换元素   
        // var para = document.createElement("p");
        // var node = document.createTextNode("这是新文本。");
        // para.appendChild(node);
        // var parent = document.getElementById("dj");
        // var child = document.getElementById("dl");
        // parent.replaceChild(para, child);
    // }
    // 定时器轮播图
    // var  i= 1;
    // var t =setInterval(function(){
    //     if(i==1){
    //         document.getElementById('img').src = '../ujx.jpg';
    //     }else{
    //         document.getElementById('img').src = '../QQ_05.jpg';
    //     }
    //     if(i==2){
    //         i=0;
    //     }
    //     i++;
    // },1000)
    // 取消定时
    // document.getElementById('but').onclick = function(){
    //     clearInterval(t);
    // }

    setTimeout(function(){   },1000);这个是延迟执行

    clearTimeout();取消定时;取消延迟执行

    // 页面跳转
    // document.getElementById('but').onclick = function(){
    //     window.location.href='http://www.baidu.com'
    // }
    // 滚动条的位置
    // scrollTo(0,0);
    //滚动条y轴位置
    // scrollY
    //滚动条X轴位置
    // scrollX
  • 相关阅读:
    算法作业实验三
    牛客练习赛53 B 美味果冻
    牛客练习赛53 C 富豪凯匹配串
    bitmat
    牛客挑战赛33 B 鸽天的放鸽序列
    树状数组
    线段树
    2019牛客国庆集训派对day7 A 2016
    背包
    作业三 -并查集
  • 原文地址:https://www.cnblogs.com/sheep-fu/p/12837256.html
Copyright © 2011-2022 走看看