zoukankan      html  css  js  c++  java
  • jquey常用代码

    1. 弹出层3秒后消失: $(".btn").show(300).delay(2000).hide(300);

    2. 加减操作

      //加

      $(".plus").click(function() {

        var mount = parseInt($(".amount").val());

        if (mount < 0 || mount >= 999) mount = 0;

        else mount += 1;

        $(".amount").val(mount);

      });

      // 减

      $(".subtract").click(function() {

        var mount = parseInt($(".amount").val());

        if (mount < 1) mount = 0;

        else mount -= 1;

        $(".amount").val(mount);

       });

    3. 动态加载数据绑定事件(ios没反应,需要另外添加一个空事件onclick="")

      $(document).on('click', '#list li', function() {
          //function code here.
      });

    4.jquery on绑定多个事件 

      $(".goods_brand_ul").on({
        mouseover: function() {
          $(this).find('i').show();
        },
        mouseleave: function() {
          $(this).find('i').hide();
        }
      }, "li");

    5.阻止冒泡

    方式一:event.stopPropagation();

            $("#div1").mousedown(function(event){
                event.stopPropagation();
            });

    方式二:return false;

            $("#div1").mousedown(function(event){
                return false;
            });

    return false 不仅阻止了事件往上冒泡,而且阻止了事件本身。

    event.stopPropagation() 则只阻止事件往上冒泡,不阻止事件本身。

  • 相关阅读:
    i5ting_doc的安装和使用
    vscode—修改默认的shell
    cookie的相关知识
    这是一段有毒的js代码,求大神解释!!!
    BFC的触发条件
    替换元素与非替换元素
    css中em的使用方法
    误操作导致ps界面中的工具栏消失
    导航栏里面的li标签和a标签的配合使用
    记录一下 elmentui 循环复选框不能选中问题
  • 原文地址:https://www.cnblogs.com/Doduo/p/6681685.html
Copyright © 2011-2022 走看看