首頁 > web前端 > js教程 > 主體

jquery實作在遊標位置插入內容的方法_jquery

WBOY
發布: 2016-05-16 16:15:28
原創
1212 人瀏覽過

本文實例講述了jquery實作在遊標位置插入內容的方法。分享給大家供大家參考。具體實作方法如下:

複製程式碼 程式碼如下:
 
 
 
    無標題頁標題> 
    腳本> 
     
        (函數($){ 
            $.fn.extend({ 
                insertAtCaret: 函數 (myValue) { 
                    var $t = $(this)[0]; 
                    if (文件.選擇) { 
                        this.focus(); 
                        sel = document.selection.createRange(); 
                        sel.text = myValue; 
                        this.focus(); 
                    } 其他 
                        if ($t.selectionStart || $t.selectionStart == '0')
   { 
                            var startPos = $t.selectionStart; 
                            var endPos = $t.selectionEnd; 
                            varscrollTop = $t.scrollTop; 
                            $t.value = $t.value.substring(0, startPos) my p.                             this.focus(); 
                            $t.selectionStart = startPos myValue.length;
                            $t.selectionEnd = startPos myValue.length 
$t.selectionEnd = startPos myValue.length 
;                             $t.scrollTop = 且滾動上方; 
                        } 其他 { 
                            this.value = myValue; 
                            this.focus(); 
                        } 
                } 
            }) 
        })(jQuery); 
        $(文檔).ready(function () { 
            $("#numd").bind("mouseleave", function () { 
                document.getElementById('keybored').style.display = 'none'; 
                document.getElementById('Nm').blur(); 
            }); 
            $("#Nm").focus(function () { 
                document.getElementById('keybored').style.display = ''; 
            }); 
            $(".readbtns").click(function () { 
                $("#Nm").insertAtCaret($(this).val()); 
            }); 
        }); 
    > 腳本
頭> 
 
   
     
           
  •  
               
               
     
               
     
           
  •  
       
 
     
     
        /> 
       
            id="keybored"> 
             
             
             
             
             
             
             
             
             
       
 
     
正文> 

希望本文對大家介紹的 jQuery 程式設計有幫助。

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!