jQuery中提供哪些钩子? [英] Which hooks are provided in jQuery?

查看:142
本文介绍了jQuery中提供哪些钩子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只有 $。cssHooks 记录在 jQuery API文档 $。valhooks 在一个句子中被提到了一个已知问题的解决方法 .val()



我想知道除jQuery之外还有多少个钩子这些2,我们应该在我们的插件开发中使用 $。valHooks 如果是这样,我认为它应该被记录为一个专门的主题而不是一句话。

解决方案

有8种不同的类型暴露的钩子。



还有一个仅用于内部使用(这是暴露的) - jQuery._queueHooks()



还有另外两个钩子: nodeHook boolHook 它们在内部使用,其功能基本上嵌入到 jQuery.attrHooks jQuery.valHooks 中。 p>

这里是重要的:




  • jQuery.attrHooks




    • 设置输入后,值将重置IE6-9中的值。

    • contenteditable 设置为false (错误#10429 )。

    • 将width和height设置为auto而不是0空字符串(错误#8150

    • 某些属性需要在IE上进行特殊呼叫 - href src width height

    • 返回未定义,在样式属性的空字符串的情况下。

    • 修复旧IE中属性的获取/设置

    • 读取属性值时如果没有定义钩子,它使用 boolHook nodeHook (与 jQuery相同)

    • 在获取/设置元素的属性时可以使用附加的钩子。




  • jQuery.propHooks




    • href / src 属性应该获得完整的标准化URL(错误#10299 Bug#12915 )。

    • 修复Safari错误地报告了选项的默认选定属性。

    • 可以在获取/设置元素的属性时使用附加的钩子




  • jQuery.Tween.propHooks



    jQuery.Tween 用于动画等。




    • 修复 scrollTop scrollLeft 在IE8中 - 将在jQuery 2.0中删除。

    • 其他动画材料。



     


  • jQuery.cssHooks strong>



    添加样式属性钩子,覆盖获取和设置样式属性的默认行为。




    • 修正获取/设置CSS属性的值 opacity

    • 修复获取 witdth height 取决于显示属性。
    • $修改宽度 height 根据框大小调整属性。
    • 修正获得边缘权。

    • 修复fo r Webkit Bug#29084 - getComputedStyle 返回百分比当指定为上/左/下/右

    • 用于 jQuery.fn.animate 以展开指定的样式属性,如 margin padding border

    • 用于其他各种 jQuery.fn.animate 相关的东西。

    • 将各种背景CSS属性设置为继承,而不使用 jQuery.cssHooks ,因为这样更短。

    • 可以是用于在获取/设置元素的单个样式属性时附加额外的钩子。




  • jQuery.valHooks




    • 修复了选项元素的黑莓4.7错误(错误#6932 )。

    • 用于阅读所选值e 选择元素。

    • 修正了阅读按钮的一些属性元素 - id name coords 。与 nodeHook 相同(见上文)

    • 修复了 radio 复选框在Webkit和其他人之间的输入。

    • 可以用于在获取/设置输入值时附加额外的钩子元素




  • jQuery.event.fixHooks



    jQuery.event.mouseHooks jQuery.event.keyHooks ,需要根据当前浏览器的支持进行修复和规范化。


  • jQuery.event.mouseHooks




    • 用于将一些属性从原始的 MouseEvent 转移到jQuery事件对象。

    • 规范化因为 event.button 没有正常化,所以(使用鼠标按钮)的浏览器,

    • 计算 pageX pageY clientX clientY 和其他如果缺少并将其设置为jQuery事件对象。 li>



  • jQuery.event.keyHooks




    • 用于从原始 KeyboardEvent 到jQuery事件对象。

    • 规范化 event.which (按钮被按下)浏览器。在原始事件中,可以是 char charCode key keyCode




从jQuery 1.9.1源。


Officially only $.cssHooks is documented in jQuery API documentation, and $.valHooks is mentioned in a sentence for a workaround to a known issue in .val().

I wonder how many hooks are there in jQuery besides of these 2, and should we use $.valHooks in our plugin development? If so, I think it should be documented as a dedicated topic instead of one-sentence only.

解决方案

There are 8 different types of exposed hooks.

There is one more for internal usage only (which is exposed) - jQuery._queueHooks().

There are also two other hooks: nodeHook and boolHook which are used internally and their functionality is basically embedded into jQuery.attrHooks and jQuery.valHooks.

Here are the important ones:

  • jQuery.attrHooks

    • Setting the type on a radio input after the value resets the value in IE6-9.
    • Set contenteditable to false on removals (Bug #10429).
    • Set width and height to auto instead of 0 on empty string (Bug #8150)
    • Some attributes require a special call on IE - href, src, width and height.
    • Return undefined in the case of empty string for the style attribute.
    • Fix get/set for the value property in old IE
    • When reading attribute values if no hook is defined it uses either boolHook or nodeHook (which is the same as jQuery.valHooks.button).
    • Could be used to attach additional hooks when getting/setting an attribute of an element.

     

  • jQuery.propHooks

    • href/src properties should get the full normalized URL (Bug #10299, Bug #12915).
    • Fix for "Safari mis-reports the default selected property of an option".
    • Could be used to attach additional hooks when getting/setting a property of an element.

     

  • jQuery.Tween.propHooks

    jQuery.Tween is used for animations and such.

    • Fix for scrollTop and scrollLeft in IE8 - will be removed in jQuery 2.0.
    • Other animation stuff.

     

  • jQuery.cssHooks

    Add in style property hooks for overriding the default behavior of getting and setting a style property.

    • Fix for getting/setting the value of the CSS property opacity.
    • Fix for getting witdth and height depending on the display property.
    • Fix for setting width and height depending on the box-sizing property.
    • Fix for getting margin-right.
    • Fix for Webkit Bug #29084 - getComputedStyle returns percent when specified for top/left/bottom/right
    • Used in jQuery.fn.animate to expand specified style properties like margin, padding and border.
    • Used in other various jQuery.fn.animate related stuff.
    • Setting various background CSS properties to inherit is achieved without using jQuery.cssHooks, because it is shorter this way.
    • Could be used to attach additional hooks when getting/setting an individual style property of an element.

     

  • jQuery.valHooks

    • Fixes a Blackberry 4.7 bug for option elements (Bug #6932).
    • Used for reading selected value for select elements.
    • Fixes reading some properties of the button element - id, name and coords. The same as nodeHook (see above).
    • Fixes the incompatibility on checking radio and checkbox inputs between Webkit and others.
    • Could be used to attach additional hooks when getting/setting the value of an input element.

     

  • jQuery.event.fixHooks

    A holder for jQuery.event.mouseHooks and jQuery.event.keyHooks which require fixing and normalizing based on the support of the current browser.

  • jQuery.event.mouseHooks

    • Used to transfer some properties from the original MouseEvent to the jQuery event object.
    • Normalizes event.which (which mouse button was used) accross browsers, because event.button is not normalized.
    • Calculates pageX, pageY, clientX, clientY and others if missing and set them to the jQuery event object.

     

  • jQuery.event.keyHooks

    • Used to transfer some properties from the original KeyboardEvent to the jQuery event object.
    • Normalizes event.which (the character code of the button which was pressed) across browsers. In the original event it could be char, charCode, key or keyCode.

From the jQuery 1.9.1 source.

这篇关于jQuery中提供哪些钩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆