jQuery:捕获点击,但仍允许选择文本

jQuery:捕获点击,但仍允许选择文本,jquery,events,bind,Jquery,Events,Bind,我正在尝试创建一个内联文本区域,用户在其中单击一段文本,文本区域将替换它 一切进展顺利,但当我尝试选择/突出显示区域中的文本时,它会显示文本区域 我注意到在Trello上,它成功地避免了这种情况 我的HTML如下所示: <h2>Your Notes</h2> <span id="notes_area" style="display: block;" data-entry-id="<%= @entry.id %>" title="Click to edit

我正在尝试创建一个内联文本区域,用户在其中单击一段文本,文本区域将替换它

一切进展顺利,但当我尝试选择/突出显示区域中的文本时,它会显示文本区域

我注意到在Trello上,它成功地避免了这种情况

我的HTML如下所示:

<h2>Your Notes</h2>
<span id="notes_area" style="display: block;" data-entry-id="<%= @entry.id %>" title="Click to edit your notes.">
    <p><%= @entry.notes.present? ? "#{@entry.notes}" : "You have not added any notes for this episode." %></p>
</span>
我想这是一个解决了的问题,但我似乎在网上找不到任何东西


谢谢

在调用“display\u inline\u note\u form()”之前,您可以检查用户是否选择了任何文本

这是getSelectedText()定义,我得到了这个


在调用“display\u inline\u note\u form()”之前,可以检查用户是否选择了任何文本

这是getSelectedText()定义,我得到了这个


听起来是一个非常简单的处理方法(这是一个补充)。我觉得自己现在没有想到这件事有点傻!我会试试看,让你知道我进展如何。非常感谢!听起来是一个非常简单的处理方法(这是一个补充)。我觉得自己现在没有想到这件事有点傻!我会试试看,让你知道我进展如何。非常感谢!
$("#notes_area").bind "mouseup", ->
    display_inline_note_form()

display_inline_note_form = ->
    # code goes here...
$("#notes_area").bind "mouseup", ->
    var selectedTxtRange = getSelectedText();
    if(selectedTxtRange.toString().length == 0)
        display_inline_note_form()
function getSelectedText()
{
    var txt = '';

     if (window.getSelection)
    {
        txt = window.getSelection();
             }
    else if (document.getSelection)
    {
        txt = document.getSelection();
            }
    else if (document.selection)
    {
        txt = document.selection.createRange().text;
            }

      return txt;    
}