Code Monkey home page Code Monkey logo

jquerydemo's Introduction

JQueryDemo

JQueryDemo

on()的多事件绑定

基本用法:

.on( events [, selector ] [, data ] )

最常见的给元素绑定一个点击事件,对比下一下快捷方式与on方式的不同:

$("#elem").click(function(){})  //快捷方式
$("#elem").on('click',function(){}) //on方式

最大的不同点就是on是可以自定义事件名,当然不仅仅只是 如此,继续往下看如此付: ** 多个事件绑定同一个函数 **

 $("#elem").on("mouseover mouseout",function(){ });

通过空格分离,传递不同的事件名,可以同时绑定多个事件 ** 多个事件绑定不同函数**

$("#elem").on({
    mouseover:function(){},  
    mouseout:function(){},
});

通过空格分离,传递不同的事件名,可以同时绑定多个事件,每一个事件执行自己的回调方法 ** 将数据传递到处理程序**

function greet( event ) {
  alert( "Hello " + event.data.name ); //Hello Redd
}
$( "button" ).on( "click", {
  name: "Redd"
}, greet );

可以通过第二参数(对象),当一个事件被触发时,要传递给事件处理函数的 以上都是on方法基本用法,具体的使用方法Jquery.on.Demo

jquerydemo's People

Contributors

happyredd avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.