问题描述:

Im having trouble having code onchange inside onchange event.

some code works and some dont work due to that.

<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>

I know there is better way to manage this code and simplify it but i have no idea how ?

EDIT:

What i want is : if i select an option , then get the values to that option, then under this category option there is radio buttons , so every check button i need to get some data displayed or removed

here is a fiddle there looks my problem .

what happens:

if i select category-->check buy -->then select others . i dont get same result as if i select directly cars ---> buy

网友答案:

try following script:
function saljkop(){ var x = "\ Sell \ buy\ "; return x ; } function price_option(){ var x = '\ \ \ Fix \ \ offer \ \ '; return x ; } function cars(){ var x = '\ '; return 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
         });
相关阅读:
Top