验证所有部件何时完成整个画面

时间:2014-03-28 13:41:23

标签: javascript jquery jquery-ui jquery-ui-sortable

我有16个部分组成了整个图片,在doc准备就绪,现在我必须在发现整个图片时通过警报进行验证。图片的某些部分也不能再次切换。我试过这段代码:

小提琴:http://jsfiddle.net/w53Ls/4/

$(function() {
        $("#puzzle").sortable({
            update: function() {
                var CorrectAnswers = ["bucata0", "bucata1", "bucata2", "bucata3", "bucata4", "bucata5", "bucata6", "bucata7", "bucata8", "bucata9", "bucata10", "bucata11", "bucata12", "bucata13", "bucata14", "bucata15"];
                var UserAnswers = [];
                $('#puzzle img').each(function(){
                    var imageId = $(this).attr("id");
                    UserAnswers += imageId.replace("recordArr_", "")+",";
                });           
                    UserAnswers = UserAnswers.substr(0,(UserAnswers.length) -1);
                if(UserAnswers == CorrectAnswers){
                    alert("You  Won");
                }
            }
        });
    });

1 个答案:

答案 0 :(得分:0)

事实证明,UserAnswers不是数组(任何更多),而CorrectAnswers是。只需加入CorrectAnswers的值,代码就可以运行

if(UserAnswers== CorrectAnswers.join(',')){
    alert("You  Won");
}

或者您将CorrectAnswers重写为逗号分隔的字符串。