0

我正在尝试在创建新产品时设置 jquery 链式选择

  1. 性别
  2. 类别
  3. 子类别

性别和类别是链接的,减去不出现的子类别!

请问有人可以给点光吗?谢谢

$(document).ready(function () {

    var $gender, $category;

    $gender = $('input[id^="product_gender_id"]');
    $category = $('#product_category_id');


    //radio only can response to 'click' event, rather than select event you wrote before.
    $gender.click(function () {

        var gender = $('input[id^="product_gender_id"]:checked').val();

        if (gender == 1); 
        else if (gender == 2); 

        jQuery.get('/products/update_category_select/' + gender, function(data){
            $("#productCategories").html(data);
        })
    });


    $category.change(function() {
        // make a POST call and replace the content

        var category = $('select#product_category_id :selected').val();

        if(category == "") category="0";
        jQuery.get('/products/update_subcategory_select/' + category, function(data){
            $("#productSubcategories").html(data);
        })
        return false;
    });

 });
4

0 回答 0