国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > 建站經(jīng)驗 > 正文

jQuery往textarea中光標所在位置插入文本的 方法

2019-11-02 14:43:51
字體:
來源:轉載
供稿:網(wǎng)友

   本文實例講述了jQuery往textarea中光標所在位置插入文本的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 <html> <head> <script src="jquery-1.8.1.min.js"></script> <script > $(function() { /* 在textarea處插入文本--Start */ (function($) { $.fn.extend({ insertContent : function(myValue, t) { var $t = $(this)[0]; if (document.selection) { // ie this.focus(); var sel = document.selection.createRange(); sel.text = myValue; this.focus(); sel.moveStart('character', -l); var wee = sel.text.length; if (arguments.length == 2) { var l = $t.value.length; sel.moveEnd("character", wee + t); t <= 0 ? sel.moveStart("character", wee - 2 * t - myValue.length) : sel.moveStart( "character", wee - t - myValue.length); sel.select(); } } 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; if (arguments.length == 2) { $t.setSelectionRange(startPos - t, $t.selectionEnd + t); this.focus()
迅雷鋪電影下載[www.aikan.tv/special/xunleipu/]
; } } else { this.value += myValue; this.focus(); } } }) })(jQuery); /* 在textarea處插入文本--Ending */ }); $(document).ready(function(){ $("#ch_button").click( function () { $("#test_in").insertContent("<upload/day_140627/201406271546349972.jpg>"); }); }); </script> </head> <body > <button id="ch_button" value="插入" >插入</button> <textarea name="content" id="test_in" rows="30" cols="100"> </textarea> </body> </html>
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 南溪县| 巨野县| 黄梅县| 巴马| 长宁区| 莒南县| 安乡县| 南安市| 长泰县| 永平县| 建湖县| 大荔县| 新野县| 紫金县| 富平县| 临夏县| 齐齐哈尔市| 右玉县| 苏尼特左旗| 芦山县| 津市市| 新泰市| 肥东县| 河间市| 班戈县| 莱西市| 保德县| 临高县| 鄂托克前旗| 江陵县| 玉树县| 长治县| 奉贤区| 新沂市| 应用必备| 桦南县| 柞水县| 安化县| 麟游县| 勃利县| 常州市|