javascirpt 함수 안에 다른 함수 호출 질문이 있습니다.

javascirpt 함수 안에 다른 함수 호출 질문이 있습니다.

QA

javascirpt 함수 안에 다른 함수 호출 질문이 있습니다.

본문

function a(){

 total = ga.value+ga2.value;

$(".result").text(total);

}

function b(chk){

   var post_f = 0;

   if(chk.checked == true){

      post_f = 3000;

   }else{

      post_f = 0;

   }

}

이런 형식인데 하고싶은것은 a함수의 total 값에 b 함수의 post_f 값을 더하고싶은데 어떻게 해야할지 여쭈어봅니다..


* b함수는 체크박스가 체크되면 3000+ , 체크를 해제하면 0 원을 추가하는 형식입니다.

이 질문에 댓글 쓰기 :

답변 1


<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
    <script type="text/javascript">
        function a(){
            var ga = $("#ga").get(0);
            var ga2 = $("#ga2").get(0);
            total = Number(ga.value)+Number(ga2.value);
            total += b($("#chk1").get(0));
            $(".result").text(total);
        }
        function b(chk){
           var post_f = 0;
           if(chk.checked == true){
              post_f = 3000;
          }else{
              post_f = 0;
          }

          return post_f;
      }
  </script>
</head>
<body>
    <input id="ga" type="text" value="10" />
    <input id="ga2" type="text" value="20" />
    <input id="chk1" type="checkbox" />
    <input type="button" value="click" onclick="a()" />
    <div class="result"></div>
</body>
</html>
답변을 작성하시기 전에 로그인 해주세요.
전체 147
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT