<bdo id='cxQWn'></bdo><ul id='cxQWn'></ul>
<tfoot id='cxQWn'></tfoot>

  • <i id='cxQWn'><tr id='cxQWn'><dt id='cxQWn'><q id='cxQWn'><span id='cxQWn'><b id='cxQWn'><form id='cxQWn'><ins id='cxQWn'></ins><ul id='cxQWn'></ul><sub id='cxQWn'></sub></form><legend id='cxQWn'></legend><bdo id='cxQWn'><pre id='cxQWn'><center id='cxQWn'></center></pre></bdo></b><th id='cxQWn'></th></span></q></dt></tr></i><div id='cxQWn'><tfoot id='cxQWn'></tfoot><dl id='cxQWn'><fieldset id='cxQWn'></fieldset></dl></div>

        <small id='cxQWn'></small><noframes id='cxQWn'>

        <legend id='cxQWn'><style id='cxQWn'><dir id='cxQWn'><q id='cxQWn'></q></dir></style></legend>
      1. 当插入符号进入特定的 div/span/a 标签以及插入符号离开标签时触发事件

        时间:2023-09-04
        <i id='LML0t'><tr id='LML0t'><dt id='LML0t'><q id='LML0t'><span id='LML0t'><b id='LML0t'><form id='LML0t'><ins id='LML0t'></ins><ul id='LML0t'></ul><sub id='LML0t'></sub></form><legend id='LML0t'></legend><bdo id='LML0t'><pre id='LML0t'><center id='LML0t'></center></pre></bdo></b><th id='LML0t'></th></span></q></dt></tr></i><div id='LML0t'><tfoot id='LML0t'></tfoot><dl id='LML0t'><fieldset id='LML0t'></fieldset></dl></div>

        • <bdo id='LML0t'></bdo><ul id='LML0t'></ul>

                <small id='LML0t'></small><noframes id='LML0t'>

                <tfoot id='LML0t'></tfoot>

              1. <legend id='LML0t'><style id='LML0t'><dir id='LML0t'><q id='LML0t'></q></dir></style></legend>

                    <tbody id='LML0t'></tbody>
                1. 本文介绍了当插入符号进入特定的 div/span/a 标签以及插入符号离开标签时触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  想法是这样的-
                  有一个 contenteditable 元素,其中包含一些文本.我正在尝试建立一个标记机制(有点像 twitter 的人在你输入@"时标记).每当用户输入@"时,当他们继续输入时,它就会显示一个带有建议和过滤器的弹出框.直到这里这很容易,我已经弄清楚了.当/仅当插入符号位于包含标记的元素上方时,我需要显示弹出框时,问题就来了.

                  The idea is this -
                  There is a contenteditable element with some text in it. Am trying to build out a tagging mechanism (kind of like twitter's people tagging when you type '@'). Whenever a user types '@', it shows up a popover with suggestions and filters when they continue typing. Until here it's easy and I have got it figured out. The problem comes when I need to show the popover if/only if the caret is over the element containing the tag.

                  <div contenteditable="">
                    <p>Some random text before
                      <a href="javascript:;"
                         class="name-suggest"
                         style="color:inherit !important;text-decoration:inherit !important">@samadams</a>
                      Some random text after</p>
                  </div>
                  

                  现在,每当用户将插入符号移到 a 标签上/单击它时,我想触发一个显示弹出框的事件,并在插入符号离开 a 标签时将其删除.(有点像焦点/模糊,但它们似乎不起作用).onmousedown 有效,但无法判断光标是否已通过键盘移动到锚标记中.

                  Now, whenever the user moves the caret over the a tag / clicks on it, I want to trigger an event that shows the popover, and remove it whenever the caret leaves the a tag. (kind of like focus / blur but they don't seem to work). onmousedown works but there is no way to tell if the cursor has been moved into the anchor tag with the keyboard.

                  另外,我在 angularjs 中这样做,因此,任何针对此的解决方案都是可取的,但不是必需的.

                  Also, am doing this in angularjs, so, any solution targeted towards that would be preferable but not necessary.

                  已经尝试让它工作一天,非常感谢任何帮助.

                  Have been trying to get this to work for a day and any help is greatly appreciated.

                  推荐答案

                  这将让您知道您的插入符号位置何时位于包含 @

                  This will let you know when your caret position is in an anchor node containing an @

                  $('#content').on('mouseup keydown keyup', function (event) {
                  
                    var sel = getSelection();
                    
                    if (sel.type === "Caret") {
                      var anchorNodeVal = sel.anchorNode.nodeValue;
                      if ( anchorNodeVal.indexOf('@') >= 0) {
                        $('#pop').show()
                      } else {
                        $('#pop').hide()
                      }
                    }
                    
                  })

                  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                  
                  <div id="content" contenteditable="">
                    <p>Some random text before
                      <a href="javascript:;"
                         class="name-suggest"
                         style="color:inherit !important;text-decoration:inherit !important">@samadams</a>
                      Some random text after</p>
                  </div>
                    
                  <div id="pop" style="display:none">Twitter node found</div>

                  您可以添加一些正则表达式来进一步验证选择.

                  You could add some regex to further validate the selection.

                  这篇关于当插入符号进入特定的 div/span/a 标签以及插入符号离开标签时触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何确保休眠版本号在 javascript 客户端中保持不变? 下一篇:如何遍历数组并运行 Grunt 任务,将数组中的每个值作为 Grunt 选项传递

                  相关文章

                  <tfoot id='BW0xc'></tfoot>

                2. <small id='BW0xc'></small><noframes id='BW0xc'>

                    <bdo id='BW0xc'></bdo><ul id='BW0xc'></ul>
                  1. <legend id='BW0xc'><style id='BW0xc'><dir id='BW0xc'><q id='BW0xc'></q></dir></style></legend>

                    1. <i id='BW0xc'><tr id='BW0xc'><dt id='BW0xc'><q id='BW0xc'><span id='BW0xc'><b id='BW0xc'><form id='BW0xc'><ins id='BW0xc'></ins><ul id='BW0xc'></ul><sub id='BW0xc'></sub></form><legend id='BW0xc'></legend><bdo id='BW0xc'><pre id='BW0xc'><center id='BW0xc'></center></pre></bdo></b><th id='BW0xc'></th></span></q></dt></tr></i><div id='BW0xc'><tfoot id='BW0xc'></tfoot><dl id='BW0xc'><fieldset id='BW0xc'></fieldset></dl></div>