关于答题注册判断分数跳转页面的问题 -问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

关于答题注册判断分数跳转页面的问题

2016-06-03 11:47:15 2569 1
     (function($) {
        $.fn.jquizzy = function(settings) {
            var defaults = {
                questions: null,
                startImg: 'images/start.gif',
                endText: '已结束!',
                shortURL: null,
                sendResultsURL: null,
                resultComments: {
                    perfect: '你是爱因斯坦么?',
                    excellent: '非常优秀!',
                    good: '很好,发挥不错!',
                    average: '一般般了。',
                    bad: '太可怜了!',
                    poor: '好可怕啊!',
                    worst: '悲痛欲绝!'
                }
            };
            var config = $.extend(defaults, settings);
            if (config.questions === null) {
                $(this).html('<div class="intro-container slide-container"><h2 class="qTitle">Failed to parse questions.</h2></div>');
                return;
            }
            var superContainer = $(this),
            answers = [],
            introFob = '    <div class="intro-container slide-container"><a class="nav-start" href="#">请认真完成测试题。准备好了吗?<br/><br/><span><img src="'+config.startImg+'"></span></a></div>    ',
            exitFob = '<div class="results-container slide-container"><div class="question-number">' + config.endText + '</div><div class="result-keeper"></div></div><div class="notice">请选择一个选项!</div><div class="progress-keeper" ><div class="progress"></div></div>',
            contentFob = '',
            questionsIteratorIndex,
            answersIteratorIndex;
            superContainer.addClass('main-quiz-holder');
            for (questionsIteratorIndex = 0; questionsIteratorIndex < config.questions.length; questionsIteratorIndex++) {
                contentFob += '<div class="slide-container"><div class="question-number">' + (questionsIteratorIndex + 1) + '/' + config.questions.length + '</div><div class="question">' + config.questions[questionsIteratorIndex].question + '</div><ul class="answers">';
                for (answersIteratorIndex = 0; answersIteratorIndex < config.questions[questionsIteratorIndex].answers.length; answersIteratorIndex++) {
                    contentFob += '<li>' + config.questions[questionsIteratorIndex].answers[answersIteratorIndex] + '</li>';
                }
                contentFob += '</ul><div class="nav-container">';
                if (questionsIteratorIndex !== 0) {
                    contentFob += '<div class="prev"><a class="nav-previous" href="#">&lt; 上一题</a></div>';
                }
                if (questionsIteratorIndex < config.questions.length - 1) {
                    contentFob += '<div class="next"><a class="nav-next" href="#">下一题 &gt;</a></div>';
                } else {
                    contentFob += '<div class="next final"><a class="nav-show-result" href="#">完成</a></div>';
                }
                contentFob += '</div></div>';
                answers.push(config.questions[questionsIteratorIndex].correctAnswer);
            }
            superContainer.html(introFob + contentFob + exitFob);
            var progress = superContainer.find('.progress'),
            progressKeeper = superContainer.find('.progress-keeper'),
            notice = superContainer.find('.notice'),
            progressWidth = progressKeeper.width(),
            userAnswers = [],
            questionLength = config.questions.length,
            slidesList = superContainer.find('.slide-container');
            function checkAnswers() {
                var resultArr = [],
                flag = false;
                for (i = 0; i < answers.length; i++) {
                    if (answers[i] == userAnswers[i]) {
                        flag = true;
                    } else {
                        flag = false;
                    }
                    resultArr.push(flag);
                }
                return resultArr;
            }
            function roundReloaded(num, dec) {
                var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
                return result;
            }
            function judgeSkills(score) {
                var returnString;
                if (score === 100) return config.resultComments.perfect;
                else if (score > 90) return config.resultComments.excellent;
                else if (score > 70) return config.resultComments.good;
                else if (score > 50) return config.resultComments.average;
                else if (score > 35) return config.resultComments.bad;
                else if (score > 20) return config.resultComments.poor;
                else return config.resultComments.worst;
            }
            progressKeeper.hide();
            notice.hide();
            slidesList.hide().first().fadeIn(500);
            superContainer.find('li').click(function() {
                var thisLi = $(this);
                if (thisLi.hasClass('selected')) {
                    thisLi.removeClass('selected');
                } else {
                    thisLi.parents('.answers').children('li').removeClass('selected');
                    thisLi.addClass('selected');
                }
            });
            superContainer.find('.nav-start').click(function() {
                $(this).parents('.slide-container').fadeOut(500,
                function() {
                    $(this).next().fadeIn(500);
                    progressKeeper.fadeIn(500);
                });
                return false;
            });
            superContainer.find('.next').click(function() {
                if ($(this).parents('.slide-container').find('li.selected').length === 0) {
                    notice.fadeIn(300);
                    return false;
                }
                notice.hide();
                $(this).parents('.slide-container').fadeOut(500,
                function() {
                    $(this).next().fadeIn(500);
                });
                progress.animate({
                    width: progress.width() + Math.round(progressWidth / questionLength)
                },
                500);
                return false;
            });
            superContainer.find('.prev').click(function() {
                notice.hide();
                $(this).parents('.slide-container').fadeOut(500,
                function() {
                    $(this).prev().fadeIn(500);
                });
                progress.animate({
                    width: progress.width() - Math.round(progressWidth / questionLength)
                },
                500);
                return false;
            });
            superContainer.find('.final').click(function() {
                if ($(this).parents('.slide-container').find('li.selected').length === 0) {
                    notice.fadeIn(300);
                    return false;
                }
                superContainer.find('li.selected').each(function(index) {
                    userAnswers.push($(this).parents('.answers').children('li').index($(this).parents('.answers').find('li.selected')) + 1);
                });
                if (config.sendResultsURL !== null) {
                    var collate = [];
                    for (r = 0; r < userAnswers.length; r++) {
                        collate.push('{"questionNumber":"' + parseInt(r + 1, 10) + '", "userAnswer":"' + userAnswers[r] + '"}');
                    }
                    $.ajax({
                        type: 'POST',
                        url: config.sendResultsURL,
                        data: '{"answers": [' + collate.join(",") + ']}',
                        complete: function() {
                            console.log("OH HAI");
                        }
                    });
                }
                progressKeeper.hide();
                var results = checkAnswers(),
                resultSet = '',
                trueCount = 0,
                shareButton = '',
                score,
                url;
                if (config.shortURL === null) {
                    config.shortURL = window.location
                };
                for (var i = 0,
                toLoopTill = results.length; i < toLoopTill; i++) {
                    if (results[i] === true) {
                        trueCount++;
                        isCorrect = true;
                    }
                    resultSet += '<div class="result-row">' + (results[i] === true ? "<div class='correct'>#"+(i + 1)+"<span></span></div>": "<div class='wrong'>#"+(i + 1)+"<span></span></div>");
                    resultSet += '<div class="resultsview-qhover">' + config.questions[i].question;
                    resultSet += "<ul>";
                    for (answersIteratorIndex = 0; answersIteratorIndex < config.questions[i].answers.length; answersIteratorIndex++) {
                        var classestoAdd = '';
                        if (config.questions[i].correctAnswer == answersIteratorIndex + 1) {
                            classestoAdd += 'right';
                        }
                        if (userAnswers[i] == answersIteratorIndex + 1) {
                            classestoAdd += ' selected';
                        }
                        resultSet += '<li class="' + classestoAdd + '">' + config.questions[i].answers[answersIteratorIndex] + '</li>';
                    }
                    resultSet += '</ul></div></div>';
                }
                score = roundReloaded(trueCount / questionLength * 100, 2);

                resultSet = '<h2 class="qTitle">' + judgeSkills(score) + '<br/> 您的分数: ' + score + '</h2>' + shareButton + '<div class="jquizzy-clear"></div>' + resultSet + '<div class="jquizzy-clear"></div>';
                superContainer.find('.result-keeper').html(resultSet).show(500);
                superContainer.find('.resultsview-qhover').hide();
                superContainer.find('.result-row').hover(function() {
                    $(this).find('.resultsview-qhover').show();
                },
                function() {
                    $(this).find('.resultsview-qhover').hide();
                });
                $(this).parents('.slide-container').fadeOut(500,
                function() {
                    $(this).next().fadeIn(500);
                });
                return false;
            });
        };
    })(jQuery);

想实现得到满分或者大于90分的情况下跳转注册页面,如何实现

取消 提交回答
全部回答(1)
  • 吴孟桥
    2019-07-17 19:26:26

    就像这样就可以的

        function judgeSkills(score) {
                var returnString;
                if (score === 100) {
                                 location.href="xxxxx";//跳转.
                            }
                else if (score > 90) return config.resultComments.excellent;
                else if (score > 70) return config.resultComments.good;
                else if (score > 50) return config.resultComments.average;
                else if (score > 35) return config.resultComments.bad;
                else if (score > 20) return config.resultComments.poor;
                else return config.resultComments.worst;
            }
    0 0
相关问答

1

回答

配置镜像仓库,这个tag标签可以改成git的sha吗? 云效是给了一个时间的tag。每次改yaml感

2022-11-24 11:41:26 316浏览量 回答数 1

1

回答

记录关闭浏览器时的 页面url?报错

2020-06-22 11:09:19 221浏览量 回答数 1

1

回答

关于MyBatis分页插件页面获取页数报错?报错

2020-06-20 17:21:58 304浏览量 回答数 1

5

回答

关于域名的注册问题

2018-06-09 08:54:32 2416浏览量 回答数 5

1

回答

域名日升期内哪些客户可以注册?

2018-01-19 14:03:03 1768浏览量 回答数 1

1

回答

钉钉下载关于跳转页面的问题

2018-01-18 11:52:39 3984浏览量 回答数 1

1

回答

thinkphp 页面跳转问题

2016-06-17 11:36:04 2058浏览量 回答数 1

1

回答

Xshell关闭之后tomcat死掉网站无法使用?

2016-05-30 15:35:17 2895浏览量 回答数 1

1

回答

关于storyboard 页面跳转问题

2016-03-13 08:38:22 1444浏览量 回答数 1

2

回答

为什么打不开云邮箱的注册页面?

2015-02-13 15:33:45 3612浏览量 回答数 2
+关注
文章
问答
问答排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载