• jQuery事件对象


    1.

    2.

    JavaScript 了 even器 的兼容性。开发人员总是会做兼容方面的处理。

    jQuery 且 还创建了一些很好用的属性和方法。

    一.事

    是 even的 是 eveneven非常在 JavaScript 解 过这些经常使用的属性和方法。这里,我们再一次演示一下。

    //

    $('input').bind('click', function (e) {                          //

    alert(e);

    });

    even 

    type

    click

    target

    的 DOM 

    data

    relatedTarget

    个 DOM 

    currentTarget

    的 DOM 与 this

    pageX/pageY

    /

    screenX/screenY

    /(非 jQuery)

    clientX/clientY

    /(非 jQuery)

    result

    timeStamp

    which

    (1,2,3)

    altKey/shiftKey/

    ctrlKey/metaKey

    是否按了 altshiftctrl(非 jQuery封装)

    meta (IE 生 meta jQuery )


    //过 event.type 

    $('input').click(function (e) {

    alert(e.type);

    });

    //过 event.target 的 DOM 

    $('input').click(function (e) {

    alert(e.target);

    });

    //过 event.data 

    $('input').bind('click', 123, function () {                     //递 dat

    alert(e.data);                                                    //

    });

    '123'[123,'abc']传递

    {user : 'Lee', age : 100}e.data[1]e.data.user

    //event.data 使

    $('input').click({user : 'Lee', age : 100},function (e) {

    alert(e.data.user);

    });

    使

    alert(e.data['user']);

    //到 di个 DOM 

    $('div').mouseover(function (e) {

    alert(e.relatedTarget);

    });

    //出 di个 DOM 

    $('div').mouseout(function (e) {

    alert(e.relatedTarget);

    });

    //个 DOM 于 this与 event.target

    $('div').click(function (e) {

    alert(e.currentTarget);

    });

    event.target 的 DOMevent.currentTarget 

    DOM而 thi的 DOM

    //

    $('div').click(function (e) {

    return '123';

    });

    $('div').click(function (e) {

    alert(e.result);

    });

    //

    $('div').click(function (e) {

    alert(e.timeStamp);

    });

    //

    $('div').mousedown(function (e) {

    alert(e.which);

    });

    //

    $('input').keyup(function (e) {

    alert(e.which);

    });

    //了 ctrl meta 使

    $('input').click(function (e) {

    alert(e.ctrlKey);

    });

    //

    $(document).click(function (e) {

    alert(e.screenY+ ',' + e.pageY + ',' + e.clientY);

    });

    冒泡和认行为 如果在页面中重叠了多个元素,而且重叠的这些元素都绑定了同一个事件,那么就会出

    //HTML 

    <distyle="200px;height:200px;background:red;">

    <inputype="button" value="/>

    </div>

    //

    $('input').click(function () { 

    });

    alert('');

    $('div').click(function () {

    alert('div ');

    });

     $(document).click(function () {

    alert('');

    });

    :当候,仅仅击 di时。了 di和 文档两个;当我们点击button时,触发了button、di文档

     这就是所谓的冒泡现象,一层一层往上。 

    jQuery event.stopPropagation()发 的事件上时,全部上层的冒泡行为都将被取消。

    $('input').click(function (e) { alert(''); e.stopPropagation();

    });

    行为区域弹 出系统菜单、点击超链接会跳转到指定页面、点击提交button会提交数据。

    $('a').click(function (e) {

    e.preventDefault();

    });

    //

    $('form').submit(function (e) {

    e.preventDefault();

    });

    时 写上:event.stopPropagation()和 event.preventDefault()

    。 还有一种简写方案取代,就是直接 return false

    $('a').click(function (e) {

    return false;

    });

    preventDefault()

    isDefaultPrevented()

    了 preventDefault()

    stopPropagation()

    isPropagationStopped()

    了 stopPropagation()

    stopImmediatePropagation()

    isImmediatePropagationStopped()

    了 stopImmediatePropagation()

    //

    $('input').keyup(function (e) { e.preventDefault();alert(e.isDefaultPrevented());

    });

    //

    $('input').click(function (e) { alert('input');e.stopImmediatePropagation();

    });

    $('input').click(function () {

    alert('input2');

    });

    $(document).click(function () {

    alert('document');

    });

    //了 stopPropagation()

    $('input').click(function (e) { e.stopPropagation();alert(e.isPropagationStopped());

    });

    //了 stopImmediatePropagation()

    $('input').click(function (e) { e.stopImmediatePropagation();alert(e.isImmediatePropagationStopped());

    });

  • 相关阅读:
    VMware Workstation CentOS7 Linux 学习之路(2)--.net core环境安装
    VMware Workstation CentOS7 Linux 学习之路(1)--系统安装
    Castle IOC概念理解
    Visual Studio Nuget还原步骤
    Js中分号使用总结
    ABP理论学习之依赖注入
    C# 中字段和属性的使用时机
    C#基础知识梳理系列
    .Net 中的IL中间语言基本语法
    项目工程结构说明(Internal)
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/8502620.html
Copyright © 2020-2023  润新知