2014-09-15 2 views
-2

onchange 이벤트 내에서 코드가 변경되는 데 문제가 있습니다.여러 데이터 센터에 잘못된 데이터가 표시되었습니다.

일부 코드는 작동하며 일부는 작동하지 않습니다.

<script> 
    $(document).on('change', '.sellkop', function() { // this is radio button 
     if ($("#rs").is(':checked')) { 
       $("#text_container").after(price_option()); 
      }; 
     if ($("#rk").is(':checked')) { 
       $("#price_container").remove(); 
       $("#licensenumber_c").css({"display": 'none' 
      }); 
     }; 
    }); 

$('#category_group').on('change', function() { // this is select options 

    if ($(this).val() == 101) { 
       $("#underKategory").css({"display": 'none'}); 
       $("#modelcontainer").remove(); 
       $(".toolimage").css({ "display": 'block'}); 

     $('.sellkop').on('change', function() { // this is radio button 
      if ($("#rs").is(':checked')) { 
       $("#licensenumber_c").css({"display": 'block'}); 
       $(".toolimage").css({"display": 'block' }); 
      } else { 
       $(".toolimage").css({"display": 'none'}); 
      } 
     }); 
    } else { 
       $(".bilar").remove(); 
       $(".toolimage").css({ "display": 'none'}); 
    } 
    if ($(this).val() == 102) { 
       $(".houses_container").remove(); 
       $(".toolimage").css({"display": 'none'}); 
       $("#underKategory").css({"display": 'inline-block'}); 
       $("#modelcontainer").remove(); 
    } 

    ///............many other values continue 
}); 
</script> 

나는이 코드를 관리하고 그것을 단순화하는 더 좋은 방법이 있다는 것을 알고 있지만 어떻게 될지 모르겠다.

편집

:

내가 원하는 것은 : 다음이 범주 옵션에서 너무마다 체크 버튼 내가 몇 가지를 얻을 필요가, 라디오 버튼 내가 옵션을 선택하면는 그 옵션에 값을 얻을 수있다 표시되거나 제거 된 데이터

여기에 내 문제가 보이는 fiddle입니다.

어떤 일이 발생합니까 : 내가 카테고리 -> 구매 확인 -> 다른 사람을 선택한 경우. 나는 ---> 스크립트 다음

+0

업데이트 코드의 가독성 ...) –

+1

왜 이벤트 핸들러 둥지 필요가 – max

+0

이있다 http://stackoverflow.com/help/how-to-ask? 한 사건이 다른 사건에 의존 하는가? – adaam

답변

-1

시도 구입 직접 차를 선택하는 경우와 동일한 결과를 얻을 해달라고 : X = "\ 판매는 는 \ 를 구입 \"
기능 saljkop() { VAR을; return x; } price_option 함수() { VAR X = '\ \ \ 수정 \ \ \ 쿠폰 \'; return x; } function cars() { var x = '\ '; 반환 X }

 $("#categories").after(saljkop()); 

     $(document).on('change', '.sellkop', function() { // this is radio button 
       if ($("#rs").is(':checked')) { 
        $("#price_container").remove(); 
         $("#text_container").after(price_option()); 

        }; 
       if ($("#rk").is(':checked')) { 

         $("#price_container").remove(); 
         $("#licensenumber_c").css({"display": 'none' 
        }); 
       }; 
      }); 

     $('#category_group').on('change', function() { // this is select options 

      if ($(this).val() == 101) { 
         $("#sellbuy").after(cars()) ; 
       $("#price_container").remove(); 
         $("#text_container").after(price_option()); 
         $("#underKategory").css({"display": 'none'}); 
         $(".toolimage").css({ "display": 'block'}); 


      } else { 
         $(".cars").remove(); 
         $(".toolimage").css({ "display": 'none'}); 
      } 
      if ($(this).val() == 102) { 
         $("#price_container").remove(); 
         $("#text_container").after(price_option()); 
         $(".toolimage").css({"display": 'none'}); 
         $("#underKategory").css({"display": 'inline-block'}); 
      } 

      ///............many other values continue 
     }); 
+0

나는 당신이 무엇을 바꾸 었는지 모른다. 지금 내 새로운 바이올린을 확인 했니?. 스크립트가 작동하지 않습니다. 보기. 카테고리 -> 구매 확인 -> 다른 카테고리를 선택하십시오. 내가 직접 자동차를 선택한다면 나는 원하는 결과를 얻지 못한다 ---> 사고. –

+0

이 코드 $ ("# categories") 뒤에 코드를 바꿉니다. after (saljkop()); –

+0

바이올린에서 모두 시도해보십시오. 하지만 내 의견에 말한 것과 같은 문제. –

관련 문제