Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery-contenteditable-确定插入符号是在图像之前还是之后_Javascript_Jquery_Redactor - Fatal编程技术网

Javascript jQuery-contenteditable-确定插入符号是在图像之前还是之后

Javascript jQuery-contenteditable-确定插入符号是在图像之前还是之后,javascript,jquery,redactor,Javascript,Jquery,Redactor,我不得不调试一个供应商api(wysiwyg),有一个问题,是否可以确定插入符号是在图像之前还是之后 插入图像时,会产生以下标记: <figure> <img src='/ur/face.png' /> <figcaption>Ur face</figcaption> </figure> 能否使用document.getSelection().anchorOffset 在使用进行测试时,如果克拉在图像之前,则该值为0,

我不得不调试一个供应商api(wysiwyg),有一个问题,是否可以确定插入符号是在图像之前还是之后

插入图像时,会产生以下标记:

<figure>
    <img src='/ur/face.png' />
    <figcaption>Ur face</figcaption>
</figure>

能否使用
document.getSelection().anchorOffset


在使用进行测试时,如果克拉在图像之前,则该值为
0
,如果克拉在图像之后,则该值为
1
(假设克拉在这两种情况下都位于
标记内)。

您是否查看该值以确定插入符号的位置?根据Redactor的演示,它实际上是一个div,具有
contenteditable=true
。所以这可能会有所帮助:@RobM。是的,我在初步的谷歌搜索中看到了这一点,但是
console.log($('.redactor editor').prop('selectionStart'))未定义。您已锁定它。它确实在按照你所描述的那样做。我尝试使用
this.selection.current().anchorOffset
的api调用,但是没有成功,但是
document.getSelection().anchorOffset
成功了。谢谢
onEnter: function(e)
{
    ....

    //-----
    // !!!!! HACK !!!!!
    //-----
    /*
    // figure
    else if (this.keydown.figure)
    {
        setTimeout($.proxy(function()
        {
            this.keydown.replaceToParagraph('FIGURE');

        }, this), 1);
    }
    */

    else if (this.keydown.figure)
    {
        var node = $(this.opts.emptyHtml);

        //  If after image (1), then we will insert after image
        if (1 === document.getSelection().anchorOffset) {

            $(this.keydown.figure).after(node);
        }

        // If before image (0), lets insert before image so users can move images down
        else {

            $(this.keydown.figure).before(node);
        }

        this.caret.start(node);

        return false;
    }
    //-----