ソースを参照

计算式光标位置设置

laiguoran 5 年 前
コミット
a1eeb2f494
2 ファイル変更29 行追加1 行削除
  1. 27 0
      app/public/js/global.js
  2. 2 1
      app/public/js/material.js

+ 27 - 0
app/public/js/global.js

@@ -802,3 +802,30 @@ jQuery.bootstrapLoading = {
         $("#progressModal").modal('hide');
     }
 };
+// 光标插入button内容
+$.fn.extend({
+    insertAtCaret: function(myValue){
+        var $t=$(this)[0];
+        if (document.selection) {
+            this.focus();
+            sel = document.selection.createRange();
+            sel.text = myValue;
+            this.focus();
+        }
+        else
+        if ($t.selectionStart || $t.selectionStart == '0') {
+            var startPos = $t.selectionStart;
+            var endPos = $t.selectionEnd;
+            var scrollTop = $t.scrollTop;
+            $t.value = $t.value.substring(0, startPos) + myValue + $t.value.substring(endPos, $t.value.length);
+            this.focus();
+            $t.selectionStart = startPos + myValue.length;
+            $t.selectionEnd = startPos + myValue.length;
+            $t.scrollTop = scrollTop;
+        }
+        else {
+            this.value += myValue;
+            this.focus();
+        }
+    }
+});

+ 2 - 1
app/public/js/material.js

@@ -545,7 +545,8 @@ $(document).ready(() => {
 
         $('#expr_select button').on('click', function () {
             const code = $(this).text();
-            $('#expr').val($('#expr').val() + code);
+            // $('#expr').val($('#expr').val() + code);
+            $('#expr').insertAtCaret(code);
         });
 
         const ExprObj = {