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
  • 相关阅读:
    [转]Windows管道系统
    [转]TCP连接的状态与关闭方式,及其对Server与Client的影响
    CreateProcess启动进程后,最好CloseHandle(pi.hProcess);CloseHandle(pi.hThread);
    [转]VC++ 通过进程名或进程ID获取进程句柄
    [装]解决sqlite3插入数据很慢的问题
    SublimeText3搭建go语言开发环境(windows)
    [转]完成端口(CompletionPort)详解 手把手教你玩转网络编程系列之三
    go语言疑问
    css中marginleft与left的区别
    jsp分页显示的代码与详细步骤
  • 原文地址:https://www.cnblogs.com/sheep-fu/p/12837256.html
Copyright © 2011-2022 走看看