当前位置: 动力学知识库 > 问答 > 编程问答 >

jquery - Javascript textarea select event

问题描述:

Is there any event for the textarea that will fire as your dragging your mouse making a selection across the text? For example, the event would fire when you first click inside of the textarea and would continue to fire as you drag your mouse making a selection. The event would stop firing after you have let go of the mouse click button, leaving some of the text selected.

网友答案:

you can catch mousemove and check for buttons properties, if buttons equals 1 then left mouse is clicked.

function fire(selectedtext){
   console.log(selectedtext);
}

$( ".textarea" ).mousemove(function( event ) {

  if(event.buttons==1)
  {
    var seltext = $(".textarea").val().substring(this.selectionStart,this.selectionEnd);
    if(seltext.length > 0) fire(seltext );

  }
});
分享给朋友:
您可能感兴趣的文章:
随机阅读: