• 页面某一个元素跟随输入框输入内容动态变化


    要考虑多种事件  如keyup ,blur

    事件绑定方法:

    多个事件绑定同一个函数

    $(document).ready(function(){

      $("input").on("keyup blur",function(){

        //代码

      });

    });

    多个事件绑定不同函数

    $(document).ready(function(){

      $("p").on({

        mouseover:function(){$("body").css("background-color","lightgray");},  

        mouseout:function(){$("body").css("background-color","lightblue");}, 

        click:function(){$("body").css("background-color","yellow");}  

      });

    });

    绑定自定义事件

    $(document).ready(function(){

      $("p").on("myOwnEvent", function(event, showName){

        $(this).text(showName + "! What a beautiful name!").show();

      });

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

        $("p").trigger("myOwnEvent",["Anja"]);

      });

    });

    传递数据到函数

    function handlerName(event) {

      alert(event.data.msg);

    }

    $(document).ready(function(){

      $("p").on("click", {msg: "You just clicked me!"}, handlerName)

    });

    适用于未创建的元素(事件委托)

    $(document).ready(function(){

      $("div").on("click","p",function(){

        $(this).slideToggle();

      });

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

        $("<p>This is a new paragraph.</p>").insertAfter("button");

      });

    });

  • 相关阅读:
    侧滑的一个注意
    viewpager+fragment结合
    webview
    动画
    <context:annotation-config> 和 <context:component-scan>的区别
    spring mvc 原理及应用
    HDU
    使用Log4Net将系统日志信息记录到记事本和数据库中
    chromium for android GPU进程结构分析
    【云图】怎样制作全国KTV查询系统?
  • 原文地址:https://www.cnblogs.com/lcddjm/p/6542889.html
Copyright © 2020-2023  润新知