我有5张相关数据的图像。如果我访问了所有图像,我需要显示带有一些消息的模态框"您已访问过所有图像"。否则"请访问所有图像"。但我得到空模式框。
$('#submit').click(function(){
$('.modal-body').html('')
if($('.img').hasClass('visited')){
$('modal-body').append('<p>you have successfully visited all the images</p>');
}else{
$('modal-body').append('<p>please visit all the images</p>');
}
});
});
这是我的HTML
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
</div>
</div>
</div>
</div>
<button type="button" class="btn btn-warning btn-lg" id="submit" data-toggle="modal" data-target="#myModal">Submit</button>
答案 0 :(得分:2)
你应该改变你的状况:
$('#submit').click(function(){
$('.modal-body').html('')
if($('.img.visited').length >= 5){
$('modal-body').append('<p>you have successfully visited all the images</p>');
}else{
$('modal-body').append('<p>please visit all the images</p>');
}
});
});
答案 1 :(得分:1)
$('.modal-body').append('<p>you have successfully visited all the images</p>');
和
$('.modal-body').append('<p>please visit all the images</p>');
答案 2 :(得分:0)
$('#submit').click(function(){
$('.modal-body').html('')
if($('.img.visited').length >= 5){
$('.modal-body').append('<p>you have successfully visited all the images</p>');
}else{
$('.modal-body').append('<p>please visit all the images</p>');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
</div>
</div>
</div>
</div>
<button type="button" class="btn btn-warning btn-lg" id="submit" data-toggle="modal" data-target="#myModal">Submit</button>