0

I have trouble to figure out how to write that code... I have chained select menu up to 3 levels meaning three menu's relate to auction site.

EACH LEVELS MENUS comes with id number and item name for sample...

menu one (first level)

id-number      item-name
---------------------------
20             ipad
21             iphone

menu two  (second level)

id-number      item-name
--------------------------
25             ipad - 4
39             ipad - 5

id-number      item-name
-------------------------
52             16gb
38             32gb

So I want to give member another option by input categories id number instead of selecting from menu by add new text field.

For sample if I selected ipad ---> ipad - 4 ---> 32gb (see above list) than that mean categories number is 202538 ( combines all Id's number). That mean that i have another options is that to put categories id number instead of selecting from menu to show items name.

My question is how can I write that code in php or jquery to input categories number like 202538 and then show items number after input categories number!

please help thanks.

4

2 回答 2

0

我将演示 PHP 中的嵌套循环。

$all_categories = array();
foreach($menu_one_ids as $id1=>$name1) {
    foreach($menu_two_ids as $id2=>$name2) {
         foreach($menu_three_ids as $id3=>$name3) {
             $all_categories[$id1.$id2.$id3] = $name1.' '.$name2.' '.$name3;
         }
    }
}

现在 $all_categories 是一个数组,其中类别编号作为键,组合名称作为值。

于 2014-01-30T00:58:48.443 回答
0

我将为您提供 UX 解决方案。这是jsFiddle

$('#cat_number').on('keyup', function(e){
    var $this = $(this);
    if($this.val().length == 6 && e.which == 13){
        var $matches = $this.val().match(/.{1,2}/g);
        if($matches){
            $.each($matches, function(i,v){
                $('select:eq('+i+')').val(v);
            });
        }
    }
});
于 2014-01-30T01:11:37.227 回答