Why does IE add a jQuery attribute for server-side element with mouseover handler?

后端 未结 1 1434
自闭症患者
自闭症患者 2021-01-22 12:55

This isn\'t a crucial piece of knowledge for me, but I would still like to know what exactly is happening here.

This is a .NET 3.5 Web Forms application. One of the pag

1条回答
  •  说谎
    说谎 (楼主)
    2021-01-22 13:32

    It's the jQuery expando attribute, it's the key in the jQuery.cache object that represents that element's data and events collections.

    In your example, in that page jQuery.cache["2"] would give you the same as $("#ctl00_CloseButton").data(), when you add an event handler or data and the object doesn't already have one, it gets a new expando (jQuery.expando) attribute with the next number in the sequence as the value.

    The reason this is done is primarily for IE, assigning handlers or data objects directly to the element makes the garbage collector behave very poorly, attaching them with this key, but no direct reference link, there's no loop and the garbage collector behaves much better.

    0 讨论(0)
提交回复
热议问题