编写一个更干净的版本的最佳方法是什么。我有一些想法,但希望在这里获得第二意见。
$('.screenshot1').click(function(){
$('#screenshot1').show();
});
$('.screenshot2').click(function(){
$('#screenshot2').show();
});
$('.screenshot3').click(function(){
$('#screenshot3').show();
});
$('.screenshot4').click(function(){
$('#screenshot4').show();
});
$('.screenshot5').click(function(){
$('#screenshot5').show();
});
$('.screenshot6').click(function(){
$('#screenshot6').show();
});
$('.screenshot7').click(function(){
$('#screenshot7').show();
});
$('#screenshot1, #screenshot2, #screenshot3, #screenshot4, #screenshot5, #screenshot6, #screenshot7, .modal-backdrop').click(function() {
$('#screenshot1').hide();
$('#screenshot2').hide();
$('#screenshot3').hide();
$('#screenshot4').hide();
$('#screenshot5').hide();
$('#screenshot6').hide();
$('#screenshot7').hide();
});
HTML 看起来像这样:
<a class="screenshot1" href="#"></a>
<div id="screenshot1">
<img src='homepage/screenshot1.jpg' alt='Screenshot 1' height='565' width='756' />
</div>
ETC....
谢谢!