편집 기록

편집 기록
  • 프로필 편집요청빌런님의 편집
    날짜2020.04.06

    jQuery로 input-radio 체크 여부 알아내기


    <html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    </head>
    <body>
        <input type="radio" name="radio12" id="radio1">
        <input type="radio" name="radio12" id="radio2">
        <button type="button" id="btn1">asd</button>
    
        <script type="text/javascript">
    
            $('#btn1').on('click',
                function() {
                    if($('input[id=radio1]:checked')){
                       window.location.replace('https://www.naver.com/');
                        console.log("라디오1");
                    }
                    else if($('input[id=radio2]:checked')){
                        window.location.replace('https://www.yahoo.com/');
                        console.log("라디오2");
                    }
                    else {
                        console.log("recontext");
                    }
                }
            );
    
        </script>
    </body>
    </html>
    

    첫번째를 체크하고 버튼을 눌렀을경우 네이버로 가는데 두번째 체크하고 버튼을 눌르면 네이버로 가는데 해결법을 몰르겠습니다. ㅠㅠ

  • 프로필 윤우섭님의 편집
    날짜2020.04.06

    html + 자바스크립트 질문답변부탁드립니


    asd

    <script type="text/javascript">
    
        $('#btn1').on('click',
            function() {
                if($('input[id=radio1]:checked')){
                   window.location.replace('https://www.naver.com/');
                    console.log("라디오1");
                }
                else if($('input[id=radio2]:checked')){
                    window.location.replace('https://www.yahoo.com/');
                    console.log("라디오2");
                }
                else {
                    console.log("recontext");
                }
            }
        );
    
    </script>
    

    첫번째를 체크하고 버튼을 눌렀을경우 네이버로 가는데 두번째 체크하고 버튼을 눌르면 네이버로 가는데 해결법을 몰르겠습니다. ㅠㅠ