简体   繁体   English

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

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

I'm using the bootbox.js prompt as the following : 我正在使用bootbox.js提示符,如下所示:

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

But this line document.execCommand('insertImage', false, result); 但是这一行document.execCommand('insertImage', false, result); seems that it doesn't work. 似乎不起作用。

I tried to do an alert instead and it worked. 我试着做一个警报,它奏效了。

Why the document.execCommand() doesn't executed ? 为什么document.execCommand()不执行? and how can I solve this problem ? 我该如何解决这个问题?

Now, this is just more than I can fit in a comment. 现在,这仅仅是我无法发表的评论。

The element that is set as contenteditable="true" has likely lost its focus ( or it's contenteditable = true is not set ) 设置为contenteditable="true"的元素可能失去了焦点(或者未设置contenteditable = true

Try 尝试

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);

Replacing currentcontenteditableid with your current contenteditable element id. 用您当前的contenteditable元素ID替换currentcontenteditableid

Give that a try, hope works ( seems likely ). 试试看,希望行得通(似乎很可能)。 If not please give us 如果没有,请给我们

  • a little more info on what bootbox.js is and what it is doing 有关bootbox.js是什么以及它在做什么的更多信息
  • some of the html 一些HTML

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

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