Javascript使用箭头键移动整个跨度

时间:2015-11-23 19:31:51

标签: javascript jquery html

我正在尝试将span标签及其内容向左或向右移动一个位置,当光标位于其中并按下Ctrl Right或Control Left时。 span标记位于contenteditable段内。我甚至没有运气获得测试消息以登录到控制台以指示光标甚至在span标记内。这是小提琴:

https://jsfiddle.net/scooke/5tp5oe7z/

使用Javascript / Jquery的

$(document).on('keyup','.move',function(e){ 
  if (e.ctrlKey && (e.which === 37 || e.which === 39)){
    //move character at right or left of span to the other side
    //to simulate the whole span moved  
  }    
  e.stopPropagation();   
 });

示例Html

<p class="parent" contenteditable="true">Bacon ipsum dolor amet jowl chicken    pork loin <span class="move">[move text]</span>tail. Short ribs meatball
<br>bresaola beef boudin hamburger, cow rump swine. Pork belly ribeye leberkas venison
<br>ground <span class="move">[move text]</span>round</p>

0 个答案:

没有答案