我正在努力提高我的编码技能并开始学习 jquery。我从简单的事情开始,比如制作一个非常简单的图像展示。这是我到目前为止编写的代码。但它似乎太长而且效率不高。有什么办法可以改善吗?
html:
<div id="galerija">
<div style="float: left; border: 1px solid red; width: 600px; height: 450px;background-image: url(images/gora_big_main.png);" class="big_image"></div>
<div style="float:left;"id="trumbai">
<div style="border: 1px solid red; cursor: pointer; width: 150px; height: 75px; background-image: url(images/gora_trumb_1.png);"class="trumb_1"></div>
<div style="border: 1px solid red; cursor: pointer; width: 150px; height: 75px; background-image: url(images/gora_trumb_2.png);"class="trumb_2"></div>
<div style="border: 1px solid red; cursor: pointer; width: 150px; height: 75px; background-image: url(images/gora_trumb_2.png);"class="trumb_3"></div>
<div style="border: 1px solid red; cursor: pointer; width: 150px; height: 75px; background-image: url(images/gora_trumb_main.png);"class="main_trumb"></div>
</div>
</div>
JS
<script type="text/javascript">
$(function(){
$(".trumb_1").click(function(){
$(".big_image").css("background-image","url('images/gora_big_1.png')");
});
});
$(function(){
$(".trumb_2").click(function(){
$(".big_image").css("background-image","url('images/gora_big_2.png')");
});
});
$(function(){
$(".trumb_3").click(function(){
$(".big_image").css("background-image","url('images/gora_big_3.png')");
});
});
$(function(){
$(".main_trumb").click(function(){
$(".big_image").css("background-image","url('images/gora_big_main.png')");
});
});
</script>