问题描述
只有 $。cssHooks
记录在和 $。valhooks
在一个句子中被提到了一个已知问题的解决方法。
我想知道除jQuery之外还有多少个钩子这些2,我们应该在我们的插件开发中使用 $。valHooks
如果是这样,我认为它应该被记录为一个专门的主题而不是一句话。
有8种不同的类型暴露的钩子。
还有一个仅用于内部使用(这是暴露的) - jQuery._queueHooks()
。
还有另外两个钩子: nodeHook
和 boolHook
它们在内部使用,其功能基本上嵌入到 jQuery.attrHooks
和 jQuery.valHooks
中。 p>
这里是重要的:
-
jQuery.attrHooks
- 设置
在
输入后,值将重置IE6-9中的值。 - 将
contenteditable
设置为false ()。 - 将width和height设置为auto而不是0空字符串()
- -
href
,src
,width
和height
。 - 返回
未定义
,在样式
属性的空字符串的情况下。 - 修复旧IE中
值
属性的获取/设置 - 读取属性值时如果没有定义钩子,它使用
boolHook
或nodeHook
(与jQuery相同)
- 在获取/设置元素的属性时可以使用附加的钩子。
- 设置
-
jQuery.propHooks
-
href
/src
属性应该获得完整的标准化URL(,)。 - 修复Safari错误地报告了选项的默认选定属性。
- 可以在获取/设置元素的属性时使用附加的钩子
-
-
jQuery.Tween.propHooks
jQuery.Tween
用于动画等。
- 修复
scrollTop
和scrollLeft
在IE8中 - 将在jQuery 2.0中删除。 - 其他动画材料。
- 修复
-
jQuery.cssHooks
strong>
添加样式属性钩子,覆盖获取和设置样式属性的默认行为。
- 修正获取/设置CSS属性的值
opacity
。 - 修复获取
witdth
和height
取决于显示
属性。 $修改
宽度
和height
根据框大小调整
属性。 - 修正获取/设置CSS属性的值
- 修正获得边缘权。
- 修复fo r -
getComputedStyle
返回百分比当指定为上/左/下/右 - 用于
jQuery.fn.animate
以展开指定的样式属性,如margin
,padding
和border
。 - 用于其他各种
jQuery.fn.animate
相关的东西。 - 将各种背景CSS属性设置为
继承
,而不使用jQuery.cssHooks
,因为这样更短。 - 可以是用于在获取/设置元素的单个样式属性时附加额外的钩子。
jQuery.valHooks
- 修复了
选项
元素的黑莓4.7错误()。 - 用于阅读所选值e
选择
元素。 - 修正了阅读
按钮的一些属性
元素 -id
,name
和coords
。与nodeHook
相同(见上文) - 修复了
radio $ c $之间的不兼容性c>和
复选框
在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
andheight
. - Return
undefined
in the case of empty string for thestyle
attribute. - Fix get/set for the
value
property in old IE - When reading attribute values if no hook is defined it uses either
boolHook
ornodeHook
(which is the same asjQuery.valHooks.button
). - Could be used to attach additional hooks when getting/setting an attribute of an element.
- Setting the type on a
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
andscrollLeft
in IE8 - will be removed in jQuery 2.0. - Other animation stuff.
- Fix for
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
andheight
depending on thedisplay
property. - Fix for setting
width
andheight
depending on thebox-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 likemargin
,padding
andborder
. - Used in other various
jQuery.fn.animate
related stuff. - Setting various background CSS properties to
inherit
is achieved without usingjQuery.cssHooks
, because it is shorter this way. - Could be used to attach additional hooks when getting/setting an individual style property of an element.
- Fix for getting/setting the value of the CSS property
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
andcoords
. The same asnodeHook
(see above). - Fixes the incompatibility on checking
radio
andcheckbox
inputs between Webkit and others. - Could be used to attach additional hooks when getting/setting the value of an input element.
- Fixes a Blackberry 4.7 bug for
jQuery.event.fixHooks
A holder for
jQuery.event.mouseHooks
andjQuery.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, becauseevent.button
is not normalized. - Calculates
pageX
,pageY
,clientX
,clientY
and others if missing and set them to the jQuery event object.
- Used to transfer some properties from the original
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 bechar
,charCode
,key
orkeyCode
.
- Used to transfer some properties from the original
From the jQuery 1.9.1 source.
这篇关于jQuery中提供哪些钩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!