백스페이스 : 커서 위치에서 삭제 > 자료실

회원로그인

오늘 본 게시물

오늘 본 페이지

없음

오늘 본 C.m.A Util

없음

자료실

자료실

백스페이스 : 커서 위치에서 삭제

페이지 정보

본문

백스페이스 : 커서 위치에서 삭제
백스페이스 : 커서 위치에서 삭제
소스예제
Tag And Script

<pre class="prettyprint lang-js linenums notranslate pre-word-wrap pretty-total-17" data-li_to="17" data-wrap="pre-word-wrap" data-lang="js">&lt;script&gt;

function backspaceAtCursor(obj) {

var $input = $(obj);

var start = $input[0].selectionStart;

var end = $input[0].selectionEnd;


// 텍스트가 선택되어 있다면 선택된 텍스트 삭제, 아니면 하나 앞 문자 삭제

if (start === end &amp;&amp; start &gt; 0) {

$input.val( $input.val().slice(0, start - 1) + $input.val().slice(end) );

$input.selectionStart = $input[0].selectionEnd = start - 1;

} else {

$input.val( $input.val().slice(0, start) + $input.val().slice(end) );

$input.selectionStart = $input[0].selectionEnd = start;

}

$input.focus();

}

&lt;/script&gt;</pre><pre class="prettyprint lang-html linenums notranslate pre-word-wrap pretty-total-2" data-li_to="2" data-wrap="pre-word-wrap" data-lang="html">&lt;input type="text" id="ex_text" class="frm_input" value="커서 위치에서 삭제" style="width:80%;" /&gt;

&lt;button type="button" class="btn" onclick="backspaceAtCursor('#ex_text');"&gt;backspace&lt;/button&gt;</pre>

추천 0 비추천 0

  • 회사 : Cginjs
  • 대표 : Cginjs
  • 주소 :
  • 메일 : admin@mysample.com
  • 사업자 등록번호 :
Copyright © Cginjs All rights reserved.
notice
Warning: Undefined variable $HTTP_ACCEPT_LANGUAGE in /cginjs/www/bbs/visit_insert.inc.php on line 131