我正在尝试刷新一个页面时,我点击“删除ELEM”,只有当最接近的“产品标题”包含一个特定的文本。下面的jquery代码不起作用。如果你有什么想法,谢谢。
null
$( document ).ready(function(){
$(".delete-item").on( "click", function( reloadEvent ) {
if( $( reloadEvent.target ).closest(".Product-details").find(".Product-title:contains('XYZ')").lenght)
{location.reload.bind(location);}
else {}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="Product-details">
<div class="Product-header">
<span class="Product-title">Product title A</span>
<div/>
<div class="Product-footer">
<div class="delete-action">
<a href="#" class="delete-item">DELETE</a>`
</div>
</div>
</div>
<div class="Product-details">
<div class="Product-header">
<span class="Product-title">Product title B</span>
<div/>
<div class="Product-footer">
<div class="delete-action">
<a href="#" class="delete-item">DELETE</a>`
</div>
</div>
</div>
null
我会这样写:
$(".delete-item").on( "click", function( ) {
if( $( this ).closest(".Product-details").find(".Product-title:contains('XYZ')").length)
{location.reload.bind(location);}
else {}
})