繁体   English   中英

具有bootbox.js提示的document.execCommand()

[英]document.execCommand() with bootbox.js prompt

我正在使用bootbox.js提示符,如下所示:

document.getElementById('picture').addEventListener('click', function(){
    bootbox.prompt('URL de l\'image: ', function(result){
        document.execCommand('insertImage', false, result);
    });
}, false);

但是这一行document.execCommand('insertImage', false, result); 似乎不起作用。

我试着做一个警报,它奏效了。

为什么document.execCommand()不执行? 我该如何解决这个问题?

现在,这仅仅是我无法发表的评论。

设置为contenteditable="true"的元素可能失去了焦点(或者未设置contenteditable = true

尝试

document.getElementById('picture').addEventListener('click', function(){

    var editabletarget = document.getElementById("currentcontenteditableid");
    bootbox.prompt('URL de l\'image: ', function(result){
        /* reset editable and focus() */
        editabletarget.setAttribute("contentEditable", true);
        editabletarget.focus();

        document.execCommand('insertImage', false, result);
    });
}, false);

用您当前的contenteditable元素ID替换currentcontenteditableid

试试看,希望行得通(似乎很可能)。 如果没有,请给我们

  • 有关bootbox.js是什么以及它在做什么的更多信息
  • 一些HTML

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM