var QuestionOption = new arrayHelper("Sort");//选项 var QuestionAnswer = new arrayHelper("Sort");//答案 var QuestionAttachments = new arrayHelper("Name");//附件 var CurQuestionCount = 0; $(function () { //文件选择 $("#FileChoose").click(function () { $("#HFilePath2").click(); }); //将file的值赋值给input $("#HFilePath2").live("change", function () { var filepath = $(this).val(); $("#filePath2").val(filepath); }); //上传附件按钮 $("#btnAdd2").click(function () { dialogHelper.Show("addpop2", 756); $("#txtResourceName2").val(""); $("#filePath2").val(""); }); //附件确定按钮 $("#FileUpload2").click(function () { FileUpload2(); }); //附件上传取消按钮 $("#addclose2").click(function () { dialogHelper.Close("addpop2"); $("#txtResourceName2").val(""); $("#filePath2").val(""); var CurQuestionCounts = $("#CurQuestionCount2").html(); QuestionAttachments.Remove(CurQuestionCounts); }); //保存按钮 $("#preserve2").click(function () { //章节Id var TheoryChapterId = $.getUrlParam("TheoryChapterId"); var typeid = $.getUrlParam("typeid"); var PaperId = $("#TestPapersId").val(); AddTitle2(TheoryChapterId, typeid, PaperId); }); }); //加载试题 function LoadTitle2(QuestionId) { $.ajax({ url: "/Teacher/TheoryQuestion/GetQuestionObj", async: false, type: "POST", data: { QuestionId: QuestionId, }, success: function (data) { QuestionOption.RemoveAll();//选项 QuestionAnswer.RemoveAll(); //答案 QuestionAttachments.RemoveAll(); //附件 var mode = data.TE; if (mode.Context != "") { $("#Context2").val(mode.Context); $("#Analysis2").val(mode.Analysis); $("#option2").find("li").remove(); $("#QuestionIdAdd2").val(mode.Id); } //选项 if (mode.OptionList != null) { var html = ""; $.each(mode.OptionList, function (i, n) { QuestionOption.Add(n); }); } //附件 if (mode.AttachmentList != null) { $.each(mode.AttachmentList, function (i1, n1) { QuestionAttachments.Add(n1); }); } createOptions2(); CreateSelect2(); //答案 if (mode.AnswerList != null) { $.each(mode.AnswerList, function (i2, n2) { QuestionAnswer.Add(n2); switch (n2.Answer1) { case 0: $("#A2").attr("checked", true); break; case 1: $("#B2").attr("checked", true); break; case 2: $("#C2").attr("checked", true); break; case 3: $("#D2").attr("checked", true); break; default: $("#option2").find("li:eq(4)").find("input").attr("checked", true); break; } }); } } }); } var type = ""; //查询对应题型 function SelectTitle2(strList) { //题型下拉列表 selectHelper.GetSelect({ url: "/Teacher/TheoryQuestion/TiXingSelList", Id: "#TypeName", value: "全部", data: { strList: strList } }); } var Index = 0; //保存题目 function AddTitle2(TheoryChapterId, typeid, PaperId) { if ($("#preserve2").val() == "编辑") { $("#preserve2").val("保存"); //启用文本框 $("#Context2").attr('disabled', false); //选项 var Fobj = $("#option2").find("li"); $.each(Fobj, function (i, n) { $(n).find("input:eq(0)").attr('disabled', false); $(n).find("input:eq(1)").attr('disabled', false); $(n).find("span").show(); }); $("#btnAdd").attr('disabled', false); //添加选项按 $("#Add").hide(); //附件 var Fobj = $("#Dappendix2").find("a"); $.each(Fobj, function (i, n) { $(n).find("b").show(); }); //解析 $("#Analysis2").attr('disabled', false); } else { if (!VerificationHelper.checkFrom("popQuestionBankAdd2")) { return false; } QuestionOption.RemoveAll();//选项 QuestionAnswer.RemoveAll();//答案 //添加试题 var obg = new Object(); obg["Id"] = $("#QuestionIdAdd2").val();//Id obg["Context"] = $("#Context2").val();//题干 obg["LibraryID"] = 1;//所属题库(理论考核/认证考试) obg["StructType"] = 2;//题目类型(枚举) obg["CharpterID"] = typeid;//认证类型Id/章节Id(对应下面的题型) obg["Analysis"] = $("#Analysis2").val();//解析 obg["Status"] = 1;//状态 开启 obg["PaperId"] = PaperId;//状态 开启 //添加选项和答案 var num = 0; var num2 = 0; var Fobj = $("#option2").find("li"); $.each(Fobj, function (i, n) { var obj = new Object(); obj["OptionName"] = $(n).find("input:eq(1)").val(); obj["Sort"] = i; QuestionOption.Add(obj); num2 = num2 + 1; //选中的为答案 if ($(n).find("label").find("input").attr("checked") == "checked") { var objs = new Object(); objs["Answer1"] = i; objs["Sort"] = i; QuestionAnswer.Add(objs); num = num + 1; } }); obg["OptionList"] = QuestionOption.GetList();//选项 obg["AnswerList"] = QuestionAnswer.GetList();//答案 obg["AttachmentList"] = QuestionAttachments.GetList();//附件 var number = 0; var lis = QuestionOption.GetList(); $.each(lis, function (i, n) { $.each(lis, function (a, b) { if (i != a) { if (n.OptionName == b.OptionName) { number = number + 1; } } }); }); if (num2 < 3) { dialogHelper.Error({ content: "请至少输入3个选项!", success: function () { } }); return false; } if (num == 0) { dialogHelper.Error({ content: "请选择正确答案!", success: function () { } }); return false; } if (num < 2) { dialogHelper.Error({ content: "多选题请至少选择两个答案!", success: function () { } }); return false; } if (number > 0) { number = 0; dialogHelper.Error({ content: "不能添加相同的选项!", success: function () { } }); return false; } $.ajax({ url: "/Teacher/TheoryQuestion/AddUpdateQuestion2", type: "POST", async: false, dataType: "json", data: JSON.stringify(obg), contentType: "application/json", success: function (data) { dialogHelper.Success({ content: "保存成功!", success: function () { Index = data.index; $("#QuestionIdAdd2").val(data.result); $("#preserve2").val("编辑"); //更新题目选择JS缓存 var old_question = AlreadyQuestionsHelper.FindRecord(obg["Id"]); if (old_question != null && old_question != undefined) { AlreadyQuestionsHelper.Remove(obg["Id"]); old_question.QuesionId = data.result; AlreadyQuestionsHelper.Add(old_question); } //激活按钮 $("#AddTitle").attr('disabled', false); $("#AddTitle").css("background-color", "#00a2e2"); $("#upward2").attr('disabled', false); $("#upward2").css("background-color", "#00a2e2"); $("#down2").attr('disabled', false); $("#down2").css("background-color", "#00a2e2"); //禁用文本框 $("#Context2").attr('disabled', true); //选项 var Fobj = $("#option2").find("li"); $.each(Fobj, function (i, n) { $(n).find("input:eq(0)").attr('disabled', true); $(n).find("input:eq(1)").attr('disabled', true); $(n).find("span").hide(); }); $("#btnAdd").attr('disabled', true); //添加选项按 $("#Add").hide(); //附件 var Fobj = $("#Dappendix2").find("a"); $.each(Fobj, function (i, n) { $(n).find("b").hide(); }); //解析 $("#Analysis2").attr('disabled', true); if (Index == 0) { $("#upward2").attr('disabled', true); $("#upward2").css("background-color", "#808080"); } QuestionOption.RemoveAll();//选项 QuestionAnswer.RemoveAll(); //答案 QuestionAttachments.RemoveAll(); //附件 } }); }, error: function (msg) { $(".background,.progressBar").hide(); } }); } } //删除选项 function DeleteSelect2(obj) { $(obj).parent().remove(); var optionName = $(obj).parent().find("input:eq(1)").val(); QuestionOption.Remove(optionName); $(obj).parent().remove(); var Fobj = $("#option2").find("li"); var num = 0; $.each(Fobj, function (i, n) { var valu = Option(i); var li = $(n).find("label").html('