Das Beispiel in diesem Artikel beschreibt, wie jquery das Einfügen von Inhalten an der Cursorposition implementiert. Teilen Sie es als Referenz mit allen. Die spezifische Implementierungsmethode lautet wie folgt: Code kopieren Der Code lautet wie folgt: 无标题页 <br> (Funktion ($) { <br> $.fn.extend({ <br> insertAtCaret: Funktion (myValue) { <br> var $t = $(this)[0]; <br> if (document.selection) { <br> this.focus(); <br> sel = document.selection.createRange(); <br> sel.text = myValue; <br> this.focus(); <br> } sonst <br> if ($t.selectionStart || $t.selectionStart == '0')<br> { <br> var startPos = $t.selectionStart; <br> var endPos = $t.selectionEnd; <br> var scrollTop = $t.scrollTop; <br> $t.value = $t.value.substring(0, startPos) myValue $t.value.substring(endPos,$t.value.length); <br> this.focus(); <br> $t.selectionStart = startPos myValue.length; <br> $t.selectionEnd = startPos myValue.length; <br> $t.scrollTop = scrollTop; <br> } else { <br> this.value = myValue; <br> this.focus(); <br> } <br> } <br> }) <br> })(jQuery); <br> $(document).ready(function () { <br> $("#numd").bind("mouseleave", function () { <br> document.getElementById('keybored').style.display = 'none'; <br> document.getElementById('Nm').blur(); <br> }); <br> $("#Nm").focus(function () { <br> document.getElementById('keybored').style.display = ''; <br> }); <br> $(".readbtns").click(function () { <br> $("#Nm").insertAtCaret($(this).val()); <br> }); <br> }); <br> id="keybored">