Javascript 无法读取属性';顶部';未定义jQuery的定义
有人能帮我修复代码,使这个脚本可以工作吗 这是我的html:Javascript 无法读取属性';顶部';未定义jQuery的定义,javascript,jquery,Javascript,Jquery,有人能帮我修复代码,使这个脚本可以工作吗 这是我的html: <div class="img-wrapper item"> <a href="/product/{{$product->id}}/{{$product->slug}}"> <a class="thumbnail" href="/product/{{$product->id}}/{{$product->slug
<div class="img-wrapper item">
<a href="/product/{{$product->id}}/{{$product->slug}}">
<a class="thumbnail" href="/product/{{$product->id}}/{{$product->slug}}" style="margin-bottom: 0px; border: none;">
<img class="media-object indexImg" src="{{$product->image}}">
</a>
</a>
<div class="tags">
@if($product->discount > 0)
<span class="label-tags"><span class="label label-danger">Išpardavimas</span></span>
@endif
<span class="label-tags"><span class="label label-info">Nauja</span></span>
</div>
<div class="option">
<button class="add-to-cart" type="button">Add to cart</button>
</div>
</div>
它与示例一起工作,因此脚本很好。我只需要正确填写这一行:
var imgtodrag = $(this).parent('.img-wrapper').find("img").eq(0);
你的问题是因为
.img wrapper
不是一个直系父母,而是一个“祖父”。使用最近的
,您将获得最近的上升点,这是本例中所需的元素。试试这个:
var imgtodrag = $(this).closest('.img-wrapper').find("img").first();
使用parent()
而不是parent()
<代码>父项()将搜索1级返回
var imgtodrag = $(this).closest('.img-wrapper').find("img").first();