当无限滚动充电时,循环其他 ajax 被打破
When infinite scroll charge the loop other ajax are broken
如何将JS中的id替换成按钮的id:
$('button').click(function(){
$('.hide_'+id).hide(1000, function(){
});
});
试试这个脚本。请检查 fiddle link.
$('button').click(function(){
var id= $(this).attr("id");
$('.hide_'+id).hide(1000, function(){
});
});
您需要使用此关键词获取id属性
$('button').click(function(){
$('.hide_'+$(this).attr("id")).hide(1000, function(){
});
});
$(document).on( 'click', 'button', function(){
var id= $(this).attr('id');
$('.hide_'+id).hide(1000, function(){
alert('hide div class_'+id);
});
});
div {
padding: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="hide_1">
<p>
<button class="btn btn-primary" id="1">Bouton</button>
</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae hic voluptate eum, sit possimus nostrum, ducimus beatae? Voluptatibus, harum. Modi error consectetur quasi alias quas obcaecati dolorem quam! Quisquam, impedit!</p>
</div>
<div class="hide_2">
<p>
<button class="btn btn-primary" id="2">Bouton</button>
</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae hic voluptate eum, sit possimus nostrum, ducimus beatae? Voluptatibus, harum. Modi error consectetur quasi alias quas obcaecati dolorem quam! Quisquam, impedit!</p>
</div>
如何将JS中的id替换成按钮的id:
$('button').click(function(){
$('.hide_'+id).hide(1000, function(){
});
});
试试这个脚本。请检查 fiddle link.
$('button').click(function(){
var id= $(this).attr("id");
$('.hide_'+id).hide(1000, function(){
});
});
您需要使用此关键词获取id属性
$('button').click(function(){
$('.hide_'+$(this).attr("id")).hide(1000, function(){
});
});
$(document).on( 'click', 'button', function(){
var id= $(this).attr('id');
$('.hide_'+id).hide(1000, function(){
alert('hide div class_'+id);
});
});
div {
padding: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="hide_1">
<p>
<button class="btn btn-primary" id="1">Bouton</button>
</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae hic voluptate eum, sit possimus nostrum, ducimus beatae? Voluptatibus, harum. Modi error consectetur quasi alias quas obcaecati dolorem quam! Quisquam, impedit!</p>
</div>
<div class="hide_2">
<p>
<button class="btn btn-primary" id="2">Bouton</button>
</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae hic voluptate eum, sit possimus nostrum, ducimus beatae? Voluptatibus, harum. Modi error consectetur quasi alias quas obcaecati dolorem quam! Quisquam, impedit!</p>
</div>