文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>2008-12-23 JQuery 学习 Vol.4

2008-12-23 JQuery 学习 Vol.4

时间:2008-12-23  来源:Givemefive

1. 事件模型
    DOM Level 0: 只有bubble phrase, 没有capture phrase。
    DOM Level 2: 有bubble phrase, 还有capture phrase。
    DOM Level 0: 事件绑定在元素属性上,每个元素每一类型的事件只能绑定一个响应事件。
    DOM Level 2: 事件通过listener的方式绑定,每个元素每一类型的事件可绑定多个响应事件。(执行顺序与绑定顺序没关系)

2. JQuery事件模型
2.1 bind
    bind(eventType,data,listener)
        Establishes a function as the event handler for the specified event type on all elements in the matched set.
    Parameters
        eventType (String) Specifies the name of the event type for which the handler is to be established. This event type can be namespaced with a suffix separated from the event name with a period character. See the remainder of this
section for details.
        data (Object) Caller-supplied data that’s attached to the Event instance as a property named data for availability to the handler functions. If omitted, the
handler function can be specified as the second parameter.
        listener (Function) The function that’s to be established as the event handler.
    Returns
        The wrapped set.

2.2 特殊的事件绑定
    eventTypeName(listener)
        Establishes the specified function as the event handler for the event type named by the method’s name. The supported commands are as follows:
    ■ blur     ■ load      ■ mousedown ■ mousemove
    ■ mouseout ■ mouseover ■ mouseup   ■ resize
    ■ scroll   ■ select    ■ submit    ■ unload
    ■ change   ■ click     ■ dblclick  ■ error
    ■ focus    ■ keydown   ■ keypress  ■ keyup

        Note that when using these shortcut methods, we cannot specify a data value to be placed in the event.data property.
    Parameters
        listener (Function) The function that’s to be established as the event handler.
    Returns
        The wrapped set.

2.3 one
    one(eventType,data,listener)
        Establishes a function as the event handler for the specified event type on all elements in the matched set. Once executed, the handler is automatically removed.
    Parameters
        eventType (String) Specifies the name of the event type for which the handler is to be established.
        data (Object) Caller-supplied data that’s attached to the Event instance for availability to the handler functions. If omitted, the handler function can be specified as the second parameter.
        listener (Function) The function that’s to be established as the event handler.
    Returns
        The wrapped set.

2.4 unbind
    unbind(eventType,listener)
    unbind(event)
        Removes events handlers from all elements of the wrapped set as specified by the optional passed parameters. If no parameters are provided, all listeners are removed from the elements.
    Parameters
        eventType (String) If provided, specifies that only listeners established for the specified event type are to be removed.
        listener (Function) If provided, identifies the specific listener that’s to be removed.
        event (Event) Removes the listener that triggered the event described by this Event instance.
    Returns
        The wrapped set.

2.5 Event 对象
altKey:  Set to true if the Alt key was pressed when the event was triggered, false if not. The Alt key is labeled Option on most Mac keyboards.
ctrlKey: Set to true if the Ctrl key was pressed when the event was triggered, false if not.
data:    The value, if any, passed as the second parameter to the bind() command when the handler was established.
keyCode: For keyup and keydown events, this returns the key that was pressed. Note that for alphabetic characters, the uppercase version of the letter will be returned, regardless of whether the user typed an uppercase or lowercase letter. For example, both a and A will return 65. You can use shiftKey to determine which case was entered. For keypress events, use the which property, which is reliable across browsers.
metaKey: Set to true if the Meta key was pressed when the event was triggered, false if not. The Meta key is the Ctrl key on PCs and the Command key on Macs.
pageX: For mouse events, specifies the horizontal coordinate of the event relative from the page origin.
pageY: For mouse events, specifies the vertical coordinate of the event relative from the page origin.
relatedTarget: For some mouse events, identifies the element that the cursor left or entered when the event was triggered.
screenX: For mouse events, specifies the horizontal coordinate of the event relative from the screen origin.
screenY: For mouse events, specifies the vertical coordinate of the event relative from the screen origin.
shiftKey: Set to true if the Shift key was pressed when the event was triggered, false if not.
target: Identifies the element for which the event was triggered.
type: For all events, specifies the type of event that was triggered (for example, click). This can be useful if you’re using one event handler function for multiple events.
which: For keyboard events, specifies the numeric code for the key that caused the event,and for mouse events, specifies which button was pressed (1 for left, 2 for middle, 3 for right). This should be used instead of button, which can’t be relied on to function consistently across browsers.

2.6 trigger
     trigger(eventType)
     Invokes any event handlers established for the passed event type for all matched elements
     Parameters
          eventType (String) Specifies the name of the event type for handlers which are to be invoked
     Returns
          The wrapped set

2.7 other trigger
     eventName()
          Invokes any event handlers established for the named event type for all matched elements.The supported commands are as follows:
     ■ blur ■ click ■ focus ■ select ■ submit
     Parameters
          none
     Returns
          The wrapped set.

2.8 toggle
     toggle(listenerOdd,listenerEven)
          Establishes the passed functions as click event handlers on all elements of the wrapped set that toggle between each other with every other trigger of a click event
     Parameters
          listenerOdd (Function) A function that serves as the click event handler for all oddnumbered clicks (the first, the third, the fifth, and so on)
          listenerEven (Function) A function that serves as the click event handler for all evennumbered clicks (the second, the fourth, the sixth, and so on)
     Returns
          The wrapped set

2.9 hover
     hover(overListener,outListener)
          Establishes handlers for the mouseover and mouseout events for matched elements. These handlers only fire when the area covered by the elements is entered and exited, ignoring transitions to child elements.
     Parameters
          overListener (Function) The function to become the mouseover handler.
          outListener (Function) The function to become the mouseout handler.
     Returns
          The wrapped set.

来自:Manning.jQuery.in.Action.Feb.2008.pdf
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载