麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > JavaScript > 正文

JavaScript讓Textare、a支持tab按鍵的方法

2019-11-02 14:16:53
字體:
供稿:網(wǎng)友

   本文實(shí)例講述了JavaScript讓Textarea支持tab按鍵的方法。分享給大家供大家參考。具體實(shí)現(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 63 64 65 66 HTMLTextAreaElement.prototype.getCaretPosition = function () { //return the caret position of the textarea return this.selectionStart; }; HTMLTextAreaElement.prototype.setCaretPosition = function (position) { //change the caret position of the textarea this.selectionStart = position; this.selectionEnd = position; this.focus(); }; HTMLTextAreaElement.prototype.hasSelection = function () { //if the textarea has selection then return true if (this.selectionStart == this.selectionEnd) { return false; } else { return true; } }; HTMLTextA
歐美電影[www.aikan.tv/xzhtml/10/]
reaElement.prototype.getSelectedText = function () { //return the selection text return this.value.substring(this.selectionStart, this.selectionEnd); }; HTMLTextAreaElement.prototype.setSelection = function (start, end) { //change the selection area of the textarea this.selectionStart = start; this.selectionEnd = end; this.focus(); }; var textarea = document.getElementsByTagName('textarea')[0]; textarea.onkeydown = function(event) { //support tab on textarea if (event.keyCode == 9) { //tab was pressed var newCaretPosition; newCaretPosition = textarea.getCaretPosition() + " ".length; textarea.value = textarea.value.substring(0, textarea.getCaretPosition()) + " " + textarea.value.substring(textarea.getCaretPosition(), textarea.value.length); textarea.setCaretPosition(newCaretPosition); return false; } if(event.keyCode == 8){ //backspace if (textarea.value.substring(textarea.getCaretPosition() - 4, textarea.getCaretPosition()) == " ") { //it's a tab space var newCaretPosition; newCaretPosition = textarea.getCaretPosition() - 3; textarea.value = textarea.value.substring(0, textarea.getCaretPosition() - 3) + textarea.value.substring(textarea.getCaretPosition(), textarea.value.length); textarea.setCaretPosition(newCaretPosition); } } if(event.keyCode == 37){ //left arrow var newCaretPosition; if (textarea.value.substring(textarea.getCaretPosition() - 4, textarea.getCaretPosition()) == " ") { //it's a tab space newCaretPosition = textarea.getCaretPosition() - 3; textarea.setCaretPosition(newCaretPosition); } } if(event.keyCode == 39){ //right arrow var newCaretPosition; if (textarea.value.substring(textarea.getCaretPosition() + 4, textarea.getCaretPosition()) == " ") { //it's a tab space newCaretPosition = textarea.getCaretPosition() + 3; textarea.setCaretPosition(newCaretPosition); } } }
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 久色免费 | 国产乱淫a∨片免费观看 | 久草视频福利在线观看 | 欧美日韩亚洲成人 | 海外中文字幕在线观看 | 亚洲精品一区二区三区免 | av播播| 日韩999 | 欧美另类69xxxxx 视频 | www.狠狠插.com| 男男羞羞视频网站国产 | 在线成人亚洲 | 久久免费视频8 | 亚洲午夜久久久精品一区二区三区 | 91色一区二区三区 | 国产一级午夜 | 看片一区二区三区 | 久久国产精 | 国产日韩一区二区三区在线观看 | 精品国产一区二区三区四区阿崩 | 视频一区二区三区在线 | 国产精品成人免费一区久久羞羞 | 精品国产一区二区三区久久久蜜月 | 免费观看视频91 | 羞羞电影在线观看 | 久久亚洲视频网 | 亚洲乱搞 | 久久精品视频国产 | 九九午夜 | 国产91久久久 | 久草在线看片 | 欧美一级毛片美99毛片 | 亚洲特黄| 亚洲成人免费网站 | 曰韩一二三区 | 一级毛片免费一级 | av在线播放免费 | 午夜视频你懂的 | 久久久久亚洲a | 成人福利软件 | 欧美成人午夜一区二区三区 |