English 中文(简体)
j 质量:数据不再使用窗户?
原标题:jQuery.data no longer works with window?

I recently upgraded our project s jQuery file from 1.4.2 to 1.4.4 and it appears that as of 1.4.3 the way we have been using jQuery.data has stopped working.

我们有这一法典:

var events = $(window).data( events );

if (events.scroll)
if (!events.scroll.include(handler))
  $(window).scroll(handler);

其目的是防止这一特定手持受到多重约束。

1.4.2中,该作品被罚款。 <代码>1.4.4,events未作界定。

function handler() {
  //do something
}

$(document).ready(function(){
  $(window).scroll(handler);
  $( div#test ).scroll(handler);

  $(window).data( events ) -> undefined
  $( div#test ).data( events ) -> Object
});

与本年度计划有什么变化? 我应如何列出<代码>window的活动?


我已将第一行改为:

var events = $(window).data( __events__ ).events;

a 视像,但将事件与平原物体联系起来的能力是令人信服的。

最佳回答

为避免物体名称相撞,更换了j Query 1.4.3+,因为window<>/code>(或任何其他平原物体)使用关键<代码>__events__>

var events = $(window).data( __events__ );

www.un.org/Depts/DGACM/index_french.htm 钥匙用于没有<代码>的任何物体。 类型: (window don t, so that it was s treatment as aible Object here).


很显然,这是一种有意识的、蓄意的改变,列入。 The jQuery 1.4.3 release notes :

JavaScript Objects
A number of changes were made to when .data() is used on JavaScript objects (or, more accurately, anything that isn’t a DOM node). To start whenever you set data on a JavaScript object the data is set directly on the object – instead of going into the internal data object store. Additionally events that are attached to objects are put in a new __events__ property that is actually a function. This was done to allow events to be attached directly to an object, be garbage collected when the object is collected, and not be serialized by a JSON serializer. These changes should make jQuery’s data and event systems much more useful on JavaScript objects.

问题回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签