浏览代码

代码冲突

lujianhong 4 年之前
父节点
当前提交
96c0072e22
共有 1 个文件被更改,包括 63 次插入66 次删除
  1. 63 66
      EBook.Web/Common/tasklib_book.js

+ 63 - 66
EBook.Web/Common/tasklib_book.js

@@ -177,8 +177,25 @@ function bindEventYS() {
     var bodyWidth = $(document.body).width();
     //不存在underline 属性下有内容,所以全部隐藏,若有就是源头数据有问题
     $('.underline').css("display", "none");
+    //给每个答题点加上ID
+    var headid = -1;//基序号
     $.each($(".yaoshi"), function (index, item) {
         $(item).attr('answer-id', index);
+        //如果是打勾题、或纠错题,加上辅助头ID
+        var parent = $(item).parent();
+        if ($(parent).hasClass('correntQue') || $(parent).hasClass('boxQue')) {
+            if(headid != -1) {
+                var gid = $(parent).attr('class').replace(/.*group(\d+).*/g, "$1");//相当于偏移序号
+                $(item).attr('parent-anid', headid +Number(gid) -1);
+            }
+            else {
+                headid = index;
+                $(item).attr('parent-anid', headid);
+            }
+        }
+        else {
+            headid = - 1;
+        }
     });
     //给音频绑定一个ID
     $.each($(".audioImg"), function (index, item) {
@@ -223,18 +240,11 @@ function bindEventYS() {
         $(item).css("width", bodyWidth + "px");
     });
     //获取两个之间的答题点
+    var index = 1;
     var checkId = 0;
-    var headId = -1;
-    var groupId = -1;
     $.each($(".multipleStart").nextUntil(".multipleEnd").filter("[class*='group']"), function (index, item) {
         checkId = $(item).find('.yaoshi').attr("answer-id");
-        var gid = $(item).attr('class').replace(/.*group(\d+).*/g, "$1");
-        if (index == 0 || groupId != gid) {
-            groupId = gid;
-            headid = checkId;
-        }
-        $(item).find('.yaoshi').attr('parent-anid', headid);
-
+        var index = $(item).attr('class').replace(/.*group(\d+).*/g, "$1");
         var ischecked = $(item).find(".underlineContent").text().indexOf("√") > -1;
         //勾选题
         if ($(item).hasClass('boxQue')) {
@@ -246,23 +256,29 @@ function bindEventYS() {
 
     //显示/隐藏习题答案
     $(".yaoshi").on("click", function () {
-        // 隐藏答案
-        var NClsName = $(this).parent().attr("class") + " correntQue";
-        var PClsName = $(this).parent().attr("class");  // 对错题有内容填写必然有correntQue,否则判断条件不成立
-        if (PClsName.indexOf(" correntQue") > -1) {
-            PClsName = PClsName.replace(" correntQue", "");
-            }
-            else {
-            PClsName = "";
-            }
-        var NextClsName = $(this).parent().next().attr("class");
-        var PreClsName = $(this).parent().prev().attr("class");
+        var ParentAnid = $(this).attr("parent-anid");
         if ($(this).attr("data-status") == "0") {
-            if (NClsName == NextClsName && NClsName.indexOf(" group") > -1) {
-                // 相同前缀且有分组才渲染
-                $(this).parent().next().find(".yaoshi").attr("data-status", "1");
-                $(this).parent().next().find(".yaoshi").attr("src", PicInfo.yaoshiShowImgUrl);
-                $.each($(this).parent().next().find(".underlineContent"), function (index, item) {
+            if (ParentAnid != undefined) {
+                $.each($(this).parents().find(".yaoshi[parent-anid='" + ParentAnid + "']"), function (index, FItem) {
+                    $(FItem).attr("data-status", "1");
+                    $(FItem).attr("src", PicInfo.yaoshiShowImgUrl);
+                    $.each($(FItem).next().find(".underlineContent"), function (index, item) {
+                        if (!$(item).hasClass("no-answer")) {
+                            $(item).css("color", "#92D050");
+                        }
+                        else {
+                            $(item).css("color", "#989898");
+                        }
+                        $(item).find(".wordStyle").css("color", "#db5d00");
+                        $(item).find(".phraseStyle").css("background-color", "#f2db8b");
+                    });
+                });
+            }
+            else{
+                $(this).attr("data-status", "1");
+                $(this).attr("src", PicInfo.yaoshiShowImgUrl);
+                //$(this).nextUntil(".yaoshi").filter(".underlineContent").css("color", "#92D050");
+                $.each($(this).nextUntil(".yaoshi").filter(".underlineContent"), function (index, item) {
                     if (!$(item).hasClass("no-answer")) {
                         $(item).css("color", "#92D050");
                     }
@@ -273,26 +289,6 @@ function bindEventYS() {
                     $(item).find(".phraseStyle").css("background-color", "#f2db8b");
                 });
             }
-            if (PClsName == PreClsName && NClsName.indexOf(" group") > -1) {
-                // 相同前缀且有分组才渲染
-                $(this).parent().prev().find(".yaoshi").attr("data-status", "1");
-                $(this).parent().prev().find(".yaoshi").attr("src", PicInfo.yaoshiShowImgUrl);
-                $(this).parent().prev().find(".underlineContent").css("color", "#989898");
-            }
-            $(this).attr("data-status", "1");
-            $(this).attr("src", PicInfo.yaoshiShowImgUrl);
-            //$(this).nextUntil(".yaoshi").filter(".underlineContent").css("color", "#92D050");
-            $.each($(this).nextUntil(".yaoshi").filter(".underlineContent"), function (index, item) {
-                if (!$(item).hasClass("no-answer")) {
-                    $(item).css("color", "#92D050");
-                }
-                else {
-                    $(item).css("color", "#989898");
-                }
-
-                $(item).find(".wordStyle").css("color", "#db5d00");
-                $(item).find(".phraseStyle").css("background-color", "#f2db8b");
-            });
             //不再存在已隐藏的钥匙,移动端回调
             if ($(".yaoshi[data-status='0']").length == 0) {
                 //添加回调
@@ -300,30 +296,27 @@ function bindEventYS() {
             }
         }
         else {
-            if (NClsName == NextClsName && NClsName.indexOf(" group") > -1) {
-                // 相同前缀且有分组才渲染
-                $(this).parent().next().find(".yaoshi").attr("data-status", "0");
-                $(this).parent().next().find(".yaoshi").attr("src", PicInfo.yaoshiHideImgUrl);
-                $.each($(this).parent().next().find(".underlineContent"), function (index, item) {
+            if (ParentAnid != undefined) {
+                $.each($(this).parents().find(".yaoshi[parent-anid='" + ParentAnid + "']"), function (index, FItem) {
+                    $(FItem).attr("data-status", "0");
+                    $(FItem).attr("src", PicInfo.yaoshiHideImgUrl);
+                    $.each($(FItem).next().find(".underlineContent"), function (index, item) {
+                        $(item).css("color", "#ffffff");
+                        $(item).find(".wordStyle").css("color", "#ffffff");
+                        $(item).find(".phraseStyle").css("background-color", "#ffffff");
+                    });
+                });
+            }
+            else { 
+                $(this).attr("data-status", "0");
+                $(this).attr("src", PicInfo.yaoshiHideImgUrl);
+                //$(this).nextUntil(".yaoshi").filter(".underlineContent").css("color", "#ffffff");
+                $.each($(this).nextUntil(".yaoshi").filter(".underlineContent"), function (index, item) {
                     $(item).css("color", "#ffffff");
                     $(item).find(".wordStyle").css("color", "#ffffff");
                     $(item).find(".phraseStyle").css("background-color", "#ffffff");
                 });
             }
-            if (PClsName == PreClsName && NClsName.indexOf(" group") > -1) {
-                // 相同前缀且有分组才渲染
-                $(this).parent().prev().find(".yaoshi").attr("data-status", "0");
-                $(this).parent().prev().find(".yaoshi").attr("src", PicInfo.yaoshiHideImgUrl);
-                $(this).parent().prev().find(".underlineContent").css("color", "#ffffff").css("background-color", "#ffffff");
-            }
-            $(this).attr("data-status", "0");
-            $(this).attr("src", PicInfo.yaoshiHideImgUrl);
-            //$(this).nextUntil(".yaoshi").filter(".underlineContent").css("color", "#ffffff");
-            $.each($(this).nextUntil(".yaoshi").filter(".underlineContent"), function (index, item) {
-                $(item).css("color", "#ffffff");
-                $(item).find(".wordStyle").css("color", "#ffffff");
-                $(item).find(".phraseStyle").css("background-color", "#ffffff");
-            });
             //添加回调
             onClickKeyHide();
         }
@@ -343,6 +336,10 @@ function bindEventYS() {
     $("td").attr("style", "");
 }
 
+// 过滤规则
+var FRules = function(DataStr) {
+    return DataStr.indexOf("") > - 1;
+};
 //学生端 处理作答区域
 var answerData = new Array();
 function handleAnswerRange() {
@@ -484,10 +481,10 @@ function handleAnswerRange() {
     var index = 1;
     var checkId = 0;
     $.each($(".multipleStart").nextUntil(".multipleEnd").filter("[class*='group']"), function (index, item) {
-        checkId = $(item).find('.yaoshi').attr("answer-id");
+        checkId = $(item).find('.yaoshi').attr("answer-id") ;
         var index = $(item).attr('class').replace(/.*group(\d+).*/g, "$1");
         var ischecked = $(item).find(".underlineContent").text().indexOf("√") > -1;
-        //勾选题
+            //勾选题
         if ($(item).hasClass('boxQue')) {
             $(item).find('.yaoshi').after("<div class='checkbox'><input id=" + checkId + " type='checkbox' onclick=this.checked=!this.checked><label for=" + checkId + "></label></div>");
             $(item).find('input').prop('checked', ischecked);