student.parctite.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. var parctiteBuilder = function() {
  2. this.buildPaper = function() {
  3. if (typeof (question) != 'undefined') {
  4. $("#questionContent").setTemplateURL(CMS_SystemConfig.VirtualDirectoryPath + '/Scripts/Business/QuestionTemplate.htm?v=1111.111ss', null, { filter_data: false });
  5. $("#questionContent").processTemplate(question);
  6. }
  7. }
  8. }
  9. function showRefAnswer() {
  10. var reg1 = /^.{1}/;
  11. var answer = "";
  12. if (question.base_question_type_id == 1) {
  13. answer = reg1.exec($(question.Answers).filter(function() { return this.provid_answer_id == question.rightAnswer; })[0].answer_name) + "";
  14. }
  15. else if (question.base_question_type_id == 3) {
  16. var a = question.rightAnswer.split(',');
  17. $(question.Answers).filter(function() { return $.inArray(this.provid_answer_id + '', a) > -1; }).each(function(i, j) {
  18. if (answer.length > 0)
  19. answer += ',';
  20. answer += reg1.exec(j.answer_name);
  21. });
  22. }
  23. else if (question.base_question_type_id == 4) {
  24. answer = $(question.Answers).filter(function() { return this.provid_answer_id == question.rightAnswer; })[0].answer_name + "";
  25. }
  26. else if (question.base_question_type_id == 2) {
  27. if (typeof (question.Answers[0]) == 'undefined')
  28. answer = '找不到对应答案';
  29. else {
  30. var a = question.rightAnswer.split(',');
  31. $(question.Answers).filter(function() { return $.inArray(this.provid_answer_id + '', a) > -1; }).each(function(i, j) {
  32. if (answer.length > 0)
  33. answer += ' | ';
  34. answer += j.answer_name;
  35. });
  36. }
  37. }
  38. else {
  39. if (typeof (question.Answers[0]) == 'undefined')
  40. answer = '找不到对应答案';
  41. else
  42. answer = question.Answers[0].answer_name;
  43. }
  44. $("#refAnswer").text(answer);
  45. $("#rightAnswerContainer").show();
  46. }
  47. // 转换填空题单体占位符
  48. function transformSingle(type, question, answer) {
  49. var body = question.content;
  50. var target = "<input type='text' class='txt_underline' />";
  51. body = transform(body, target);
  52. return body;
  53. }
  54. // 替换占位符
  55. function transform(content, target) {
  56. var reg = /【.*?】/;
  57. return content.replace(reg, target);
  58. }
  59. function transformMuilte(typeid, typeName,question, answer) {
  60. var body = question.content;
  61. var answers = ""; //GetTextAnswer(question.id).split('|');
  62. for (var a in question.Answers) {
  63. var an = "";
  64. // if (answers.length > a)
  65. // an = answers[a];
  66. var ctrlName = "ST-" + typeid + "-" + question.test_question_Id;
  67. var target = "<input type='text' questionid='" + question.test_question_Id + "' answertype='" + typeName +
  68. "' class='txt_underline' name='" + ctrlName + "' value=\"" + an + "\"" +
  69. "onblur=\"Check_text2(this,'" + ctrlName + "','" + question.Answers[a].provid_answer_id + "','" + question.test_question_Id + "');\" />";
  70. body = transform(body, target);
  71. }
  72. return body;
  73. }
  74. // 保存答案
  75. var Save = function (question_id, answer) {
  76. $("[id$=hd_right_questionid]").val(question_id);
  77. right_answers=answer;
  78. }
  79. // 单选题
  80. function Check_rad(obj, answerid, questionid) {
  81. Save(questionid, answerid);
  82. }
  83. // 多选题
  84. function Check_chk(obj, ctrlName, answerid, questionid) {
  85. var answers = $("input[name=" + ctrlName + "]:checked");
  86. var answer = "";
  87. if (answers.length > 0) {
  88. answers.each(function (i, j) {
  89. if (answer.length > 0)
  90. answer += "|";
  91. answer += $(j).val();
  92. });
  93. }
  94. Save(questionid, answer);
  95. }
  96. // 填空题和计算题
  97. function Check_text (obj, answerid, questionid) {
  98. if ($(obj).val().length > 0) {
  99. Save(questionid, $(obj).val());
  100. }
  101. }
  102. // 简答题和论述题
  103. function Check_area (obj, answerid, questionid) {
  104. if ($(obj).text().length > 0) {
  105. Save(questionid, $(obj).text());
  106. }
  107. }
  108. // 多项填空题
  109. function Check_text2 (obj, ctrlName, answerid, questionid) {
  110. var inputs = $("input[name=" + ctrlName + "]");
  111. var answer = "";
  112. inputs.each(function (i, j) {
  113. if (answer.length > 0)
  114. answer += "|";
  115. answer += clearKeyChar($(j).val());
  116. });
  117. Save(questionid, answer);
  118. }
  119. // 将答案半角字符修改成全角
  120. var clearKeyChar = function(val) {
  121. return val.replace(/\|/gi, "│")
  122. }