how to show an auto suggestion div near the caret position in a content-editable div

痞子三分冷 提交于 2019-12-11 04:54:23

问题


I have a content-editable div and I am trying to show an auto-suggestion near to my caret positon when i type a character.


i am looking for something like this.. but the below code is not working

        var editor  = document.getElementById('myDiv');
        var t=$(editor).offset().top;
        var l=$(editor).offset().left;
        var caretPosition = getCaretPosition(editor);
        var autoSuggestionDiv = document.getElementById('divResult');
        autoSuggestionDiv.style.top = t + caretPosition + "px";
        autoSuggestionDiv.style.left = l + caretPosition + 20 + "px";
        var inputSearch = getCharacterPrecedingCaret(editor);
        var dataString = 'searchword='+ inputSearch;
        if(inputSearch!='')
        {
            $.ajax({
            type: "POST",
            url: "Search.aspx",
            data: dataString,
            cache: false,
            success: function(html)
            {
            $("#divResult").html(html).show();
            }
            });
        }

来源:https://stackoverflow.com/questions/15159692/how-to-show-an-auto-suggestion-div-near-the-caret-position-in-a-content-editable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!