zoukankan      html  css  js  c++  java
  • BOM事件

    1.焦点事件

      onfocus获取焦点事件
      onblur失去焦点事件
      obj.focus()给指定的元素设置焦点
      obj.blur()取消指定的元素的焦点
      obj.select()选择指定元素里面的文本内容

    HTML

    <input type="text" name="" id="" value="请输入内容" />
    <input type="button" name="" id="" value="全选" />
    

    JS

    var txt=document.getElementsByTagName("input");
    //输入框提示文字
    //当输入框获得焦点
    txt[0].onfocus=function(){
    	if(this.value=="请输入内容"){
    		this.value="";
    	}
    }
    //失去焦点
    txt[0].onblur=function(){
    	if(this.value==""){
    		this.value="请输入内容";
    	}
    }
    
    //页面一打开文本框就获得焦点
    txt[0].focus();
    //全选文本框内的内容
    txt[1].onclick=function(){
    	txt[0].select();
    }
    

    2.Event对象

    event:事件对象,当一个事件发生的时候,和当前这个对象发生的这个事件有关 的一些详细的信息被临时保存到一个指定地方-event对象,供我们在需要的时候调用。

    注意:事件对象必须在一个事件调用的函数里面使用才有内容
    用来获取事件的详细信息:鼠标位置、键盘按键
    Event对象的兼容:ev=ev||window.event
    Event对象下的获取鼠标位置:clientX clientY

    function fn(ev){
        var ev=ev||event;
        alert(ev);
    }
    document.onclick=fn;
    

    3.事件流  

      (1)事件冒泡     

        取消冒泡:ev.cancelBubble=true;   

      (2)事件捕获     

        Ie下是没有的,在绑定事件中,标准下是有的

  • 相关阅读:
    Java web学习总结
    java web知识点
    SSH进阶之路
    file /etc/httpd/conf.d/php.conf from install of php-5.6.37-1.el7.remi.x86_64 conflicts with file from package mod_php71w-7.1.18-1.w7.x86_64
    centos7上安装php5.6
    centos7 删除php
    centos7删除yum安装的php
    给服务器加内存
    Hyperledger Fabric 开发环境搭建 centos7系统
    79
  • 原文地址:https://www.cnblogs.com/yangxue72/p/8126929.html
Copyright © 2011-2022 走看看