zoukankan      html  css  js  c++  java
  • event.preventDefault() vs. return false

    使用jquery方式的话,以下是等效的

    return false === event.stopPropagation + event.preventDefault() 

    //1. event.preventDefault()
    $('a').click(function (e) {
    // custom handling here
    e.preventDefault();
    });
    //2. return false
    $('a').click(function () {
    // custom handling here
    return false;
    });

    非jquery的情况,例如<a href="demo.html" onclick="return false;">

    其作用只是阻止默认事件行为,不能停止事件冒泡

    https://stackoverflow.com/questions/1357118/event-preventdefault-vs-return-false

  • 相关阅读:
    meta标签
    Vue(day8)
    Vue(day7)
    Vue(day6)
    Flex布局
    Vue(day5)
    jquery.data()&jquery.extend()
    Promise对象
    Vue(day4)
    Vue(day3)
  • 原文地址:https://www.cnblogs.com/imust2008/p/9187918.html
Copyright © 2011-2022 走看看