Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the new adapter added by jQuery1.6c

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of how to use the new adapter of jQuery1.6c, the content is detailed and easy to understand, the operation is simple and fast, and it has certain reference value. I believe you will gain something after reading this article on how to use the new adapter of jQuery1.6c. Let's take a look at it.

In the attributes module of jQuery (github is divided in this way, but it is difficult to say that the coupling is so high), three such objects, valHooks,attrHooks and propHooks, are added, corresponding to val,attr and prop respectively. Prop is new, indicating jQuery's determination to distinguish between attributes and features, but IE6/7 is still unable to distinguish between them, so attr basically covers the functionality of prop.

Let's take a look at their respective applications.

/ / jQuery.style method if (value! = = undefined) {/ / = slightly = / / If a hook was provided, use that value, otherwise just set the specified value if (! hooks | | ("set" in hooks) | | (value = hooks.set (elem) Value)! = = undefined) {/ / Wrapped to prevent IE from throwing errors when 'invalid' values are provided / / Fixes bug # 5509 try {style [name] = value } catch (e) {} else {/ / If a hook was provided get the non-computed value from there if (hooks & & "get" in hooks & & (ret = hooks.get (elem, false, extra))! = undefined) {return ret } / / Otherwise just get the value from the style object return style [name];} / / jQuery.fn.val method if (! arguments.length) {if (elem) {hooks = jQuery.valHooks [elem.nodeName.toLowerCase ()] | | jQuery.valHooks [elem.type] If (hooks & & "get" in hooks & & (ret = hooks.get (elem, "value"))! = = undefined) {return ret;} return (elem.value | | "") .replace (rreturn, ");} return undefined } / / = slightly = hooks = jQuery.valHooks [this.nodeName.toLowerCase ()] | | jQuery.valHooks [this.type]; / / If set returns undefined, fall back to normal setting if (! hooks | | ("set" in hooks & & hooks.set (this, val, "value") = = undefined)) {this.value = val } / / jQuery.attr method hooks = jQuery.attrHooks [name] | (jQuery.nodeName (elem, "form") & & formHook); if (value! = = undefined) {if (value = null | | (value = = false & &! rspecial.test (name) {jQuery.removeAttr (elem, name); return undefined } else if (hooks & & "set" in hooks & & notxml & (ret = hooks.set (elem, value, name))! = = undefined) {return ret;} else {/ / Set boolean attributes to the same name if (value = true & &! rspecial.test (name)) {value = name } elem.setAttribute (name, "" + value); return value;}} else {if (hooks & & "get" in hooks & & notxml) {return hooks.get (elem, name);} else {ret = elem.getAttribute (name) / / Non-existent attributes return null, we normalize to undefined return ret = null? Undefined: ret;}} / / jQuery.prop method hooks = jQuery.propHooks [name]; if (value! = = undefined) {if (hooks & & "set" in hooks & & (ret = hooks.set (elem, value, name))! = undefined) {return ret } else {return (elem [name] = value);}} else {if (hooks & & "get" in hooks & & (ret = hooks.get (elem, name))! = undefined) {return ret;} else {return elem [name] }} / / jQuery.event.add if (! special.setup | | special.setup.call (elem, data, namespaces, eventHandle) = false) {/ / Bind the global event handler to the element if (elem.addEventListener) {elem.addEventListener (type, eventHandle, false) } else if (elem.attachEvent) {elem.attachEvent ("on" + type, eventHandle);} / / jQuery.event.remove if (! special.teardown | | special.teardown.call (elem, namespaces) = false) {jQuery.removeEvent (elem, type, elemData.handle);}

It can be found that it is still very organized. These adapters are used to handle special properties, styles, or events. For these attributes, styles or events, we can add the corresponding solutions to the adapter through the feature sniffing of the browser. With these adapters, jQuery can save a lot of if else decisions, and when the official version is released, you can happily announce how many percentage faster these methods are!

It can be found that it is still very organized. These adapters are used to handle special properties, styles, or events. For these attributes, styles or events, we can add the corresponding solutions to the adapter through the feature sniffing of the browser. With these adapters, jQuery can save a lot of if else decisions, and when the official version is released, you can happily announce how many percentage faster these methods are!

It can be found that it is still very organized. These adapters are used to handle special properties, styles, or events. For these attributes, styles or events, we can add the corresponding solutions to the adapter through the feature sniffing of the browser. With these adapters, jQuery can save a lot of if else decisions.

This is the end of the article on "how to use the new adapters in jQuery1.6c". Thank you for reading! I believe that everyone has a certain understanding of "how to use the new adapter of jQuery1.6c". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report