If 문이 올바르게 작동하지 않는 jQuery 문제

호머 _J

다음 코드가 있습니다.

$(document).ready(function(){

    $("[name=q58]").each(function (i) {
        $(this).click(function () {
            var selection = $(this).val();
            alert('Q58 Value = '+selection)
            if (selection == '1') {
                $("#region").show();

                $("[name=q59]").each(function (i) {
                    $(this).click(function () {
                        var selection = $(this).val();
                        alert('Q59 Value = '+selection)
                        if (selection == '1') {
                            $("#location").show();
                            $("input:radio[name^='east-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='north-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='scotland-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='southeast-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='southwest-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("#east, #north, #scotland, #southeast, #southwest").hide();
                            $("#central").show();
                        }
                        else if (selection == '2') {
                            $("#location").show();
                            $("input:radio[name^='central-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='north-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='scotland-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='southeast-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='southwest-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("#central, #north, #scotland, #southeast, #southwest").hide();
                            $("#east").show();
                        }
                        else if (selection == '3') {
                            $("#location").show();
                            $("input:radio[name^='central-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='east-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='scotland-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='southeast-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='southwest-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("#central, #east, #scotland, #southeast, #southwest").hide();
                            $("#north").show();
                        }
                        else if (selection == '4') {
                            $("#location").show();
                            $("input:radio[name^='central-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='east-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='north-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='southeast-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='southwest-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("#central, #east, #north, #southeast, #southwest").hide();
                            $("#scotland").show();
                        }
                        else if (selection == '5') {
                            $("#location").show();
                            $("input:radio[name^='central-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='east-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='north-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='scotland-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='southwest-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("#central, #east, #north, #scotland, #southwest").hide();
                            $("#southeast").show();
                        }
                        else if (selection == '6') {
                            $("#location").show();
                            $("input:radio[name^='central-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='east-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='north-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='scotland-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='southeast-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("#central, #east, #north, #scotland, #southeast").hide();
                            $("#southwest").show();
                        }
                        else {
                            $("#location").hide();
                            $("input:radio[name^='central-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='east-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='north-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='scotland-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='southeast-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("input:radio[name^='southwest-']").each(function(i) {
                                   this.checked = false;
                            });
                            $("#central, #east, #north, #scotland, #southeast, #southwest").hide();
                        }             
                    });
                });

            }
            else if (selection == '10') {
                $("input:radio[name^='central-']").each(function(i) {
                       this.checked = false;
                });
                $("input:radio[name^='east-']").each(function(i) {
                       this.checked = false;
                });
                $("input:radio[name^='north-']").each(function(i) {
                       this.checked = false;
                });
                $("input:radio[name^='scotland-']").each(function(i) {
                       this.checked = false;
                });
                $("input:radio[name^='southeast-']").each(function(i) {
                       this.checked = false;
                });
                $("input:radio[name^='southwest-']").each(function(i) {
                       this.checked = false;
                });
                $("#central, #east, #north, #scotland, #southeast, #southwest").hide();
                $("#location").hide();
                $("#region").show();
            }
            else {
                $("input:radio[name^='q59']").each(function(i) {
                       this.checked = false;
                });
                $("input:radio[name^='central-']").each(function(i) {
                       this.checked = false;
                });
                $("input:radio[name^='east-']").each(function(i) {
                       this.checked = false;
                });
                $("input:radio[name^='north-']").each(function(i) {
                       this.checked = false;
                });
                $("input:radio[name^='scotland-']").each(function(i) {
                       this.checked = false;
                });
                $("input:radio[name^='southeast-']").each(function(i) {
                       this.checked = false;
                });
                $("input:radio[name^='southwest-']").each(function(i) {
                       this.checked = false;
                });
                $("#region").hide();
                $("#location").hide();
                $("#central").hide();
            }             
        });
    });




});

JsFiddle의 예 : JsFiddle의 예 : http://jsfiddle.net/ExPUu/1/

다음과 같은 이상한 동작이 발생합니다.

사용자의 선택은 Aftersales, 그들은 다음을 참조 q59하고 중 하나를 선택할 수 있습니다 Central또는 East다음 참조 q60및 추가 옵션을 선택합니다. 이것은 잘 작동합니다.

사용자가 선택 Bus, Coach and Engines하면 더 이상 옵션이 표시되지 않습니다. 다시 정상적으로 작동합니다.

이상한 동작은 사용자 Sales가이 항목을 선택 하면 선택 하면 선택할 수 있어야합니다. Central또는 East클릭 한 Sales것 외에 다른 항목이 없으면 제대로 작동합니다. 그러나 그들이 선택 Aftersales하고 마음을 바꾸고 선택했다면 또는 Sales하나를 선택하면 표시 되며 그렇지 않아야합니다.CentralEastq60

내 jQuery 코드를 살펴 봤는데 내가 어디로 잘못 가고 있는지 알 수 없습니다. 아니면 이것이 이상한가요?

쪽으로

이벤트 바인딩에 문제가 있습니다.의 경우 AfterSales클릭 이벤트를 q59에 바인딩합니다. 따라서 사용자 Sales가 q59에서 무언가를 선택 하고 선택하면 클릭 핸들러가 실행됩니다. 다음은 문제를 일으키는 코드입니다.

$("[name=q59]").each(function (i) {
  $(this).click(function () { ...

You can avoid this by either unbinding the event or using some condition inside the event to check whether AfterSales is selected or Sales is selected.

To unbind use

$("[name=q59]").each(function (i) {
                $(this).unbind('click');
                });

in else part.

See working fiddle

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

양식 제출이 jquery에서 올바르게 작동하지 않습니다.

분류에서Dev

자바 스크립트 / JQuery 중첩 if 문이 올바르게 작동하지 않음

분류에서Dev

자바 스크립트 / JQuery 중첩 if 문이 올바르게 작동하지 않음

분류에서Dev

Oracle Update 문이 올바르게 작동하지 않습니다.

분류에서Dev

Javascript setInterval if 문이 올바르게 작동하지 않음

분류에서Dev

Android if-else 문이 올바르게 작동하지 않음

분류에서Dev

Javascript 조건문이 올바르게 작동하지 않음

분류에서Dev

JavaScript If 문이 올바르게 작동하지 않음

분류에서Dev

If 문이 올바르게 작동하지 않습니다.

분류에서Dev

If 문이 올바르게 작동하지 않습니다.

분류에서Dev

Javascript에서 올바르게 작동하지 않는 if 문

분류에서Dev

JavaScript에서 올바르게 작동하지 않는 Switch 문

분류에서Dev

문자열 하위가 올바르게 작동하지 않음

분류에서Dev

Hibernate Crtieria 및 제한이 올바르게 작동하지 않음

분류에서Dev

이미지를 올바르게 정렬하는 문제

분류에서Dev

jquery 모바일 문제, 작동하지 않는 기능

분류에서Dev

htaccess mod_rewrite 문제-정규식이 올바르게 작동하지 않습니다.

분류에서Dev

구문 분석 된 Double이 올바르게 작동하지 않는 이유는 무엇입니까?

분류에서Dev

Sweetalert 패키지 및 jQuery submit ()이 올바르게 작동하지 않음

분류에서Dev

jQuery Mobile 외부 패널이 올바르게 작동하지 않음

분류에서Dev

JavaScript의 조건부 및 for 루프에서 break 문이 올바르게 작동하지 않는 것 같습니다.

분류에서Dev

C의 getopt ()가 if 문 후에 올바르게 작동하지 않습니다.

분류에서Dev

SQL Select 문 SubSelect가 올바르게 작동하지 않습니다.

분류에서Dev

연결 문자열 NSPredicate가 올바르게 작동하지 않습니다.

분류에서Dev

데이터 프레임 분할 및 분해 방법이 올바르게 작동하지 않는 문제를 해결하는 방법은 무엇입니까?

분류에서Dev

JavaScript로 Codemirror 데이터 제출이 올바르게 작동하지 않음

분류에서Dev

C 프로그래밍 언어 : if 문이 문자에서 올바르게 작동하지 않습니다.

분류에서Dev

자바 스크립트 정렬이 문자열로 올바르게 작동하지 않음

분류에서Dev

태그가 올바르게 구현되지 않은 문제

Related 관련 기사

  1. 1

    양식 제출이 jquery에서 올바르게 작동하지 않습니다.

  2. 2

    자바 스크립트 / JQuery 중첩 if 문이 올바르게 작동하지 않음

  3. 3

    자바 스크립트 / JQuery 중첩 if 문이 올바르게 작동하지 않음

  4. 4

    Oracle Update 문이 올바르게 작동하지 않습니다.

  5. 5

    Javascript setInterval if 문이 올바르게 작동하지 않음

  6. 6

    Android if-else 문이 올바르게 작동하지 않음

  7. 7

    Javascript 조건문이 올바르게 작동하지 않음

  8. 8

    JavaScript If 문이 올바르게 작동하지 않음

  9. 9

    If 문이 올바르게 작동하지 않습니다.

  10. 10

    If 문이 올바르게 작동하지 않습니다.

  11. 11

    Javascript에서 올바르게 작동하지 않는 if 문

  12. 12

    JavaScript에서 올바르게 작동하지 않는 Switch 문

  13. 13

    문자열 하위가 올바르게 작동하지 않음

  14. 14

    Hibernate Crtieria 및 제한이 올바르게 작동하지 않음

  15. 15

    이미지를 올바르게 정렬하는 문제

  16. 16

    jquery 모바일 문제, 작동하지 않는 기능

  17. 17

    htaccess mod_rewrite 문제-정규식이 올바르게 작동하지 않습니다.

  18. 18

    구문 분석 된 Double이 올바르게 작동하지 않는 이유는 무엇입니까?

  19. 19

    Sweetalert 패키지 및 jQuery submit ()이 올바르게 작동하지 않음

  20. 20

    jQuery Mobile 외부 패널이 올바르게 작동하지 않음

  21. 21

    JavaScript의 조건부 및 for 루프에서 break 문이 올바르게 작동하지 않는 것 같습니다.

  22. 22

    C의 getopt ()가 if 문 후에 올바르게 작동하지 않습니다.

  23. 23

    SQL Select 문 SubSelect가 올바르게 작동하지 않습니다.

  24. 24

    연결 문자열 NSPredicate가 올바르게 작동하지 않습니다.

  25. 25

    데이터 프레임 분할 및 분해 방법이 올바르게 작동하지 않는 문제를 해결하는 방법은 무엇입니까?

  26. 26

    JavaScript로 Codemirror 데이터 제출이 올바르게 작동하지 않음

  27. 27

    C 프로그래밍 언어 : if 문이 문자에서 올바르게 작동하지 않습니다.

  28. 28

    자바 스크립트 정렬이 문자열로 올바르게 작동하지 않음

  29. 29

    태그가 올바르게 구현되지 않은 문제

뜨겁다태그

보관