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
  • 相关阅读:
    验证码处理函数
    Apache2.2下载及安装
    centos6.4、6.5、7.0环境下载及安装
    数据库实务 实务隔离级别
    InnoDB 锁
    索引常见问题处理
    数据库索引 B-Tree索引 hash索引
    JVM学习-(2)
    jvm学习-(1)
    linux杂记
  • 原文地址:https://www.cnblogs.com/sheep-fu/p/12837256.html
Copyright © 2011-2022 走看看