2013-10-18 3 views
0

그래서 누군가가 체크 박스를 클릭 할 때마다 어떻게 값을 변경 시킬지 궁금합니다. 기본적으로 총 토지 양도세 (PLTT + TLTT)$0이되어야합니다. checkbox가있는 if 문은 수행하기가 싫지만 프로그램이 제대로 작동하지 않습니다. 내가해야 할 조언이 필요합니까?체크 박스 변경 값을 만드는 방법은 무엇입니까?

<!doctype html> 
<html> 
    <head> 
     <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script> 
    </head> 
    <body> 
     <table bgcolor="#D4D4D4" border="1" width="450" height="60"> 
      <tr> 
       <td width="175" align="center">Land Transfer Tax Calculator</td> 
      </tr> 
     </table> 

     <table border="0" bgcolor="#E7E7E7" width="450" height="69"> 
      <tr> 
       <td height="30" align="center">Enter the Price:<input type="textbox" name="x1" id="price" style="width:150px"></td><br> 
      </tr> 
      <tr> 
       <td align="center" ><font size="2">(no commas or decimals)</font></td> 
      </tr> 
      <tr> 
       <td align="center"><input type="checkbox" id="check1" value="">First time home buyers</td> 
      </tr> 
      <tr> 
       <td align="center"><input type="button" id="calculate" style="" value="Calculate"></td> 
      </tr> 
     </table> 

     <table bgcolor="#E7E7E7" width="450" border="0" > 
      <tr> 
       <td align="center">Provincial Land Transfer Tax (PLTT)</td> 
       <td align="center">Toronto Land Transfer Tax (TLTT)</td> 
       <td align="center">Total Land Transfer Tax (PLTT + TLTT)</td> 
      </tr> 
      <tr> 
       <td align="center"><input type="textbox" id="provincal" value="" style="width:135px" disabled/></td> 
       <td align="center"><input type="textbox" id="toronto" value="" style="width:135px" disabled/></td> 
       <td align="center"><input type="textbox" id="final" value="" style="width:135px" disabled></td> 
      </tr> 
     </table> 
    </body> 

    <script type="text/javascript"> 
     $("#calculate").click(function() { 
      var x1 = $("#price").val(); 
      var y1,y2,y3,y4; 

      if (x1 <= 50000) { 
       y1=x1*0.005; //Provinical 
       y2=x1*0.005; //Toronto 
       y3=y1+y2; 
      } 
      else if (x1 <= 250000) { 
       y1=(x1*0.01)-275; //Provinical 
       y2=y1; //Toronto 
       y3=y1+y2; 
      } 
      else if (x1<=400000) { 
       y1=(x1*0.015)-1525; //Provinical 
       y2=(x1*0.01)-275; //Toronto 
       y3=y1+y2; 
      } 
      else if (x1>=400001) { 
       y1=(x1*0.02)-3525; 
       y2=y1-750; 
       y3=y1+y2; 
      } 

      $("#rebate").val(y4); 
      $("#final").val(y3); 
      $("#toronto").val(y2); 
      $("#provincal").val(y1); 
     }); 
    </script> 
</html> 
+0

무엇을 시도 했습니까? jquery를 사용하면 이것은 비교적 사소한 것처럼 보입니다. 확인란의 변경 사항을 읽고 확인란이 켜져 있으면 #final을 $ 0로 설정합니다. – Think

+0

중복 : http://stackoverflow.com/questions/901712/check-checkbox-checked-property-using-jquery – yarl

답변

0

를 사용하여 클릭 이벤트 핸들러 계산의 끝에서 (그러나 텍스트 상자의 값을 변경하기 전에)이 시도하고 적절한 내부의 계산을 실행합니다. jsFiddle link

$("#check1").click(function() { 
    if ($("#check1").prop("checked")) { 
     $("#final").val(0); 
     $("#toronto").val(0); 
     $("#provincal").val(0); 
    } 
    else{ 
     calc(); 
    } 
}); 
+0

나를 도와 주셔서 대단히 감사합니다 !!!!! – CommanderMed

+0

피험자의 문제를 해결하려면 대답으로 표시하십시오. –

0

if 문은 어떻게 작성 했습니까?

는/체크되지 않은 이벤트를 확인 처리 할 수 ​​

if ($("#check1").is(":checked")) { 
    y3=0; 
} 
0

시도해 볼 수 있습니다.

$("checkbox#check1").on('click',function(){ 
    if($(this).is(":checked")){ 
     $("input#price").val(0); 

    }else{ 
     calculate(); 
    } 
}) 
관련 문제