<div class="codetitle"> <span><a style="CURSOR: pointer" data="6579" class="copybut" id="copybut6579" onclick="doCopy('code6579')"><u>코드 복사</u></a></span> 코드는 다음과 같습니다.</div> <div class="codebody" id="code6579"> <br><!DOCTYPE html PUBLIC "-//W3C/ /DTD XHTML 1.0 전환//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br><html xmlns="http://www.w3 .org/ 1999/xhtml"> <br><head> <br><title>jQuery는 장바구니에 있는 여러 항목의 총 가격 계산을 구현합니다</title> <br><script type= "text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script> <br><script>$(function() { <br> $(".add").click(function(){ <br>var t=$(this).parent().find('input[class*=text_box]'); <br>t .val(parseInt (t.val()) 1) <br>setTotal(); <br>}) <br>$(".min").click(function(){ <br>var t=$( this).parent ().find('input[class*=text_box]'); <br>t.val(parseInt(t.val())-1) <br>if(parseInt(t.val() )<0 ){ <br>t.val(0); <br>} <br>setTotal() <br>}) <br>function setTotal(){ <br>var s=0; >$(" #tab td").each(function(){ <br>s =parseInt($(this).find('input[class*=text_box]').val())*parseFloat($( this).find ('span[class*=price]').text()); <br>$("#total").html(s.toFixed(2)); >} <br>setTotal(); <br><br>}) <br></script> <br><body> "> <br><tr> <br><td> <br><span>단가:</span><span class="price">1.50</span> <br><input class="min" name="" type="button" value="-" /> <br><input class="text_box" name="" type="text" value="1 " /> <br><input class="add" name="" type="button" value=" " /> <br></td> <br></tr> <br> <tr> <br><td> <br><span>단가:</span><span class="price">3.95</span> <br><입력 클래스= "min" name=" " type="button" value="-" /> <br><input class="text_box" name="" type="text" value="1" /> ><input class="add" name="" type="button" value=" "></td> <br></tr> 🎜><br>< ;p>총 가격:<label id="total"></label></p> <br></body> <br> ><br> </td> </tr> </div>