Browse Source

不允许多层上标下标

Michael Wang 5 năm trước cách đây
mục cha
commit
75377914b8
1 tập tin đã thay đổi với 19 bổ sung3 xóa
  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);