在下面的代碼中,我希望在頁面加載時顯示第一個圖像,但是它不顯示任何內容,並且在Firebug中沒有錯誤。如何用JQuery獲取第一張圖片的圖片源?
我怎樣才能得到這條線的工作:
$('img#main').attr('src', $('img:first').src);
全碼:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('jquery', '1.5');
google.setOnLoadCallback(function() {
$('img.thm').css({opacity: 0.7});
$('img#main').attr('src', $('img:first').src); //doesn't work
$('img.thm').width(80).click(function() {
$('img#main').attr('src', this.src);
});
$('img.thm').mouseover(function() {
$(this).css({opacity: 1.0});
});
$('img.thm').mouseout(function() {
$(this).css({opacity: 0.7});
});
});
</script>
<style type="text/css">
img.thm {
cursor: hand;
cursor: pointer;
}
</style>
</head>
<body>
<div id="menu">
<img class="thm" src="images/test1.png"/>
<img class="thm" src="images/test2.png"/>
<img class="thm" src="images/test3.png"/>
</div>
<div id="content">
<img id="main"/>
</div>
</body>
</html>