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
  • 相关阅读:
    压缩感知的由来
    VS2010自动崩溃问题
    随机过程好书推荐
    Kernel PCA
    稀疏性与L1范数
    豆瓣关于计算机视觉的书评及介绍
    压缩感知测量矩阵的研究现状(转)
    信号的功率谱、能量谱、频谱的区别(转)
    vc++ & matlab 换行符号
    arg min 的含义
  • 原文地址:https://www.cnblogs.com/sheep-fu/p/12837256.html
Copyright © 2011-2022 走看看