什么是prevObject,为什么我的选择器会返回? [英] What is prevObject and why is my selector returning that?
问题描述
我正在尝试从元素中获取顶部,但我收到此错误,这意味着什么以及如何摆脱它?
I'm trying to obtain the top from an element but I'm getting this error, what does it means and how do I get rid of it?
$(".hover").offset().top
>Uncaught TypeError: Cannot read property 'top' of undefined
$(".hover")
[div.hover, prevObject: x.fn.x.init[1], context: document, selector: ".hover", jquery: "2.0.3", constructor: function…]
[prevObject: x.fn.x.init[1], context: document, selector: ".hover", jquery: "2.0.3", constructor: function…]
当我尝试将其放入嵌套的droppable中时,会发生在jqueryui的drop事件中。
This happens inside the drop event of jqueryui when I try to drop it into a nested droppable.
$.fn.makeDroppable = function(){
$(this).droppable({
drop: function(event, ui) {
console.log($(".hover"));
console.log($(".hover").offset().top);
$(".hover").makeDroppable().removeClass("hover");
},
over: function(event, ui) {
$("<div>").addClass("hover").appendTo(this);
}
});
}
$(".container").makeDroppable();
<div class="container"></div>
推荐答案
如果DOM没有元素,jQuery将返回prevObject正在运行jQuery。您可能会在运行时看到源中的元素,但它并未绑定到DOM,因此它显示了prevObject。尝试再次检查您的js文件,或者在此处粘贴代码。
jQuery returns prevObject if the DOM does not have the element for which jQuery is being run. You might see the element in your source at the run-time however, it is not not bound to the DOM and therefore, it shows prevObject. Try checking your js file again or else paste the code here.
这篇关于什么是prevObject,为什么我的选择器会返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!