zoukankan      html  css  js  c++  java
  • 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());

    });

  • 相关阅读:
    已经菜到不行了 PAT 1010. Radix (25)
    容斥 或者 单调栈 hihocoder #1476 : 矩形计数 和 G. Snake Rana 2017 ACM Arabella Collegiate Programming Contest
    React的Context的使用方法简介
    canvas的进阶
    canvas的基础入门
    CSS3 中弹性盒模型--容器的属性
    creat-react-app搭建的项目中按需引入antd以及配置Less和如何修改antd的主题色
    D3.js 动画 过渡效果 (V3版本)
    D3.js(v3)+react 制作 一个带坐标轴与比例尺的折线图
    D3.js 弦生成器(V3版本)
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/8502620.html
Copyright © 2011-2022 走看看