onClick功能仅在首次点击时起作用

时间:2017-11-20 22:07:09

标签: javascript jquery

我正在尝试开发一个函数,在每次点击时使用imagepicker加载一部分照片。我知道所有的功能都是独立工作的,但为了让它们与图像选择器一起工作,我做了一个更大的编译功能。该功能仅在第一次点击时有效。我似乎无法解决为什么会这样。有人能指出这种情况发生的地点和原因吗?感谢。

var feature_lst = new Array("oder", "gill_size", "spore_print_color", "habitat");

var min = 0;

function onClick(json_lst, min){
$(document).ready(function(){
    var oder = {
        images : ["odor_almond.jpeg", "odor_anise.jpeg", "odor_creosote.jpg", "odor_fishy.jpg", "odor_foul.jpg", "odor_musty.jpeg", "odor_none.jpeg", "odor_pungent.jpg", "odor_spicy .jpg"],
        values : ["a", "l", "c", "y", "f", "m", "n", "p", "s"],
        text : ["Almond", "Anise", "Creosote", "Fishy", "Foul", "Musty", "None", "Pungent", "Spicy"]
    };

    var gill_size = {
        images : ["broad_gillsize.jpeg", "narrow_gillsize.jpeg"],
        values : ["b", "n"],
        text : ["Broad gill-size", "Narrow gill-size"]
    };

    var spore_print_color = {
        images : ["spc_black.jpg","spc_brown.jpg", "spc_buff.jpg", "spc_chocolate.jpeg", "spc_green.png", "spc_orange.jpeg", "spc_purple.jpeg", "spc_white.jpeg", "spc_yellow.jpg"],
        values : ["k", "n", "b", "h", "r", "o", "u", "w", "y"],
        text : ["Black", "Brown", "Buff", "Chocolate", "Green", "Orange", "Purple", "White", "Yellow"]
    };

    var habitat = {
        images : ["hab_grasses.jpeg", "hab_leaves.jpeg", "hab_meadow.jpg", "hab_path.jpg", "hab_urban.jpg", "hab_waste.jpeg", "hab_woods.jpg"],
        values : ["g", "l", "m", "p", "u", "w", "d"],
        text : ["Grasses", "Leaves", "Meadows", "Paths", "Urban", "Waste", "Woods"]
    };

    var container = []

    $("select").imagepicker({
        clicked:function(){
            //Sends image value
            var value = this.val();
            container.push(value);
            //Remove Options
            document.getElementsByClassName('picker')[0].options.length = 0
            //Adds New Options
            var max = json_lst.length - 1, select = document.getElementsByClassName('picker')[0]

            if(min <= max){
                console.log(min)
                for (i = 0; i <= eval(eval(json_lst)[min]).images.length - 1; i++){
                    var opt = document.createElement("option");
                    opt.setAttribute('value', eval(json_lst[min]).values[i]);
                    opt.setAttribute('data-img-src', '../static/feature_imgs/' + eval(json_lst[min]).images[i]);
                    opt.setAttribute('innerHTML', eval(json_lst[min]).text[i]);
                    select.appendChild(opt);

                                }
                            $('select').imagepicker();
                            min = min + 1
                            console.log(min)
                            return min
                            }
                else {
                    alert("You have made a selection for each parameter. Please hit the submit button. ");
                    }

            }
        });
    });
}

我在<script>标记

中调用该函数
onClick(feature_lst, min);

0 个答案:

没有答案