태그 글 보관함: script

jquery .bind(), .live()

bind()
http://api.jquery.com/bind/

————————————————————————————————————————————–

Description: Attach a handler to an event for the elements.

  • version added: 1.0.bind( eventType,  [eventData,] handler(eventObject) )

    eventTypeA string containing one or more JavaScript event types, such as “click” or “submit,” or custom event names.

    eventDataA map of data that will be passed to the event handler.

    handler(eventObject)A function to execute each time the event is triggered.

  • version added: 1.4.3.bind( eventType,  [eventData,] preventBubble )

    eventTypeA string containing one or more JavaScript event types, such as “click” or “submit,” or custom event names.

    eventDataA map of data that will be passed to the event handler.

    preventBubbleSetting the third argument to false will attach a function that prevents the default action from occurring and stops the event from bubbling. The default is true.

  • version added: 1.4.bind( events )

    eventsA map of one or more JavaScript event types and functions to execute for them.

————————————————————————————————————————————–

– 사용 방법

  1. 단일
    $(“input”).bind(“click”, function(){  ……… });
  2. 2개 이상
    $(“input”).bind(“click”, function(){ ……… }).bind(“blur”,function(){ …… });
  3. 2개이상
    $(“input”).bind({
    click: function() { ……. },
    blur: function() { …….. }
    });

 

live()
http://api.jquery.com/live/

————————————————————————————————————————————–
Description: Attach a handler to the event for all elements which match the current selector, now and in the future.

  • version added: 1.3.live( eventType, handler )

    eventTypeA string containing a JavaScript event type, such as “click” or “keydown.” As of jQuery 1.4 the string can contain multiple, space-separated event types or custom event names, as well.

    handlerA function to execute at the time the event is triggered.

  • version added: 1.4.live( eventType, eventData, handler )

    eventTypeA string containing a JavaScript event type, such as “click” or “keydown.” As of jQuery 1.4 the string can contain multiple, space-separated event types or custom event names, as well.

    eventDataA map of data that will be passed to the event handler.

    handlerA function to execute at the time the event is triggered.

  • version added: 1.4.3.live( events )

    eventsA map of one or more JavaScript event types and functions to execute for them

————————————————————————————————————————————–

– 사용 방법 bind()와 동일


– 차이점 속도

http://www.ravelrumba.com/blog/event-delegation-jquery-performance/

 

– 각종 이벤트

마우스 키보드 기타
  click   focus   resize
  dbclick   keydown   scroll
  mousedown   keypress   select
  mousemove   keyup   submt
  mouseout   blur   unload
  mouseover   –   error
  mouseup   –   load
  –   –   change