문제) 아래 작은 이미지를 클릭시 상단의 큰 이미지와 텍스트 가격이 바뀌도록 jquery를 이용해 제작.


<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

<style>

li {

list-style: none;

display: inline-block;

text-align: center;

}

</style>

<script src="jquery-1.11.3.js"></script>

<script src="http://code.jquery.com/jquery-latest.js"></script>

<script>

$(document).ready(function() {

$('li').click(function(e) {

var imgSrc = $(this).children('img').attr('src');

var price = $(this).children('.price').text();

$('#bigPic').attr('src', imgSrc);

$('#bigPrice').text(price);

});

});

function setImg(imgSrc) {

$('#bigPic').attr('src', imgSrc);

}       

</script>

</head>

<body>

<p id="bigInfo">

<img width="300" height="300" src="img/selMsg.jpg" id="bigPic">

가격: <span id="bigPrice">15000</span>

<ul id="photoList">

<li><img src="product01.jpg"> <br />가격: <span

class="price">10000</span></li>

<li><img src="product02.jpg"> <br />가격: <span

class="price">12000</span></li>

<li><img src="product03.jpg"> <br />가격: <span

class="price">13000</span></li>

<li><img src="product04.jpg"> <br />가격: <span

class="price">15000</span></li>

</ul>

</body>

</html>





Posted by netyhobby
,