소스 검색

不允许多层上标下标

Michael Wang 5 년 전
부모
커밋
75377914b8
1개의 변경된 파일19개의 추가작업 그리고 3개의 파일을 삭제
  1. 19 3
      src/features/OnlineExam/Examing/TextQuestionView.vue

+ 19 - 3
src/features/OnlineExam/Examing/TextQuestionView.vue

@@ -337,13 +337,21 @@ export default {
       this.studentAnswer = this.$refs.answerDiv.innerHTML;
     },
     textSup() {
+      const origHMTL = this.$refs.answerDiv.innerHTML + "";
       getSelection()
         .getRangeAt(0)
         .surroundContents(document.createElement("sup"));
-      this.studentAnswer = this.$refs.answerDiv.innerHTML;
+      if (
+        this.$refs.answerDiv.querySelector("sup sup, sub sub, sup sub, sub sup")
+      ) {
+        console.log("不允许多层上标下标");
+        this.$refs.answerDiv.innerHTML = origHMTL;
+      } else {
+        this.studentAnswer = this.$refs.answerDiv.innerHTML;
+      }
     },
     undoTextSup() {
-      getSelection().modify("extend", "left", "character");
+      // getSelection().modify("extend", "left", "character");
       let selRange = getSelection().getRangeAt(0);
       var documentFragment = selRange.extractContents();
       var text = new Text(documentFragment.textContent);
@@ -351,10 +359,18 @@ export default {
       this.studentAnswer = this.$refs.answerDiv.innerHTML;
     },
     textSub() {
+      const origHMTL = this.$refs.answerDiv.innerHTML + "";
       getSelection()
         .getRangeAt(0)
         .surroundContents(document.createElement("sub"));
-      this.studentAnswer = this.$refs.answerDiv.innerHTML;
+      if (
+        this.$refs.answerDiv.querySelector("sup sup, sub sub, sup sub, sub sup")
+      ) {
+        console.log("不允许多层上标下标");
+        this.$refs.answerDiv.innerHTML = origHMTL;
+      } else {
+        this.studentAnswer = this.$refs.answerDiv.innerHTML;
+      }
     },
     textInput($event) {
       // console.log($event.target.innerHTML);