• 总结5.6 jsDOM操作2


            /*失去焦点*/
            document.getElementById('input').onblur = function(){
                console.log('失去焦点');
            }//鼠标到input文本框外时,控制台显示失去焦点
            /*获取焦点*/
            document.getElementById('input').onfocus = function() {
                console.log('获取焦点');
            }//鼠标在input文本框内时,控制台显示获取焦点
            /*添加元素*/
            var p = document.createElement('p');//创建新元素类型
            var nod = document.createTextNode('新段落');//创建新元素内容
            p.appendChild(nod);//形成添加的新元素
            document.getElementById("ids").appendChild(p);//将元素添加进对象
            /*删除元素*/
            var parent = document.getElementById('id');//找到父元素
            var child = document.getElementsByName('p');//找到父元素中需要删除的元素
            parent.removechild(child);//删除元素
            /*替换元素*/
            var para = document.createElement('div');
            var nod1 = document.createTextNode('新段落一');
            div.appendChild(nod1);//与添加元素时创建新元素一样
            var parent = document.getElementById('id');
            var child = document.getElementsByName('p');//找到父元素中需要替换的元素
            parent.replacechild(child);
            var y = setInterval(function(i){
                i++;
            },2000);//定时器,2000代表每2000ms执行一次函数
            document.getElementById('id').onclick = function(){
                clearInterval(y);
            }//取消定时器
            var z = setTimeout(function(j){
                j--;
            },2000);//延时器,执行跟定时器类似,但是只在规定时间后执行一次
            document.getElementById('id').onclick = function(){
                clearTimeout(z);
            }//取消延时器
            document.getElementById('id').onclick = function(){
                window.location.href = 'http://www.baidu.com';
            }//点击id元素时,跳转到百度界面
            document.getElementById('id1').onclick = function(){
                window.history.back();
            }//点击id1元素时,后退到上个界面
            document.getElementById('id2').onclick = function(){
                window.onload = function(z) {
                    z++;
                }
            }//当元素id2加载完后,执行内部function
  • 相关阅读:
    jenkins自动化部署前端项目
    jenkins自动部署java项目
    Jenkins插件修改为国内源
    jenkins搭建以及初始化
    gitlab-ci集成sonarqube完成代码检测
    微信小程序模板消息后端代码
    解决上传图片到服务器 水印文字显示框框不显示文字的问题
    ES transport client使用
    签发的用户认证token超时刷新策略
    api权限管理系统与前后端分离实践
  • 原文地址:https://www.cnblogs.com/HighKK/p/12837018.html
Copyright © 2020-2023  润新知