Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.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 删除上载的图像时';从编辑器中删除_Javascript_Laravel_Server - Fatal编程技术网

Javascript 删除上载的图像时';从编辑器中删除

Javascript 删除上载的图像时';从编辑器中删除,javascript,laravel,server,Javascript,Laravel,Server,我创建了一个编辑器,将图像添加到帖子中,并直接上传到我的服务器,最后插入到文本编辑器主体中,如: <img src="http://mydev.io:8000/storage/c6bc9b4b0ae0244058a4181f8e84007d-1.jpg"> 问题是,当用户从编辑器中删除此图像时,如何从服务器中删除此图像正如其他人所说,您需要显示更多代码,以便人们可以查看内容编辑器的详细信息,但是像这样的事情是非常粗略的,你可以做什么来检测变化事件,并开始计算图像是否存在 var

我创建了一个编辑器,将图像添加到帖子中,并直接上传到我的服务器,最后插入到文本编辑器主体中,如:

<img src="http://mydev.io:8000/storage/c6bc9b4b0ae0244058a4181f8e84007d-1.jpg">


问题是,当用户从编辑器中删除此图像时,如何从服务器中删除此图像

正如其他人所说,您需要显示更多代码,以便人们可以查看内容编辑器的详细信息,但是像这样的事情是非常粗略的,你可以做什么来检测变化事件,并开始计算图像是否存在

var currentImages = [];

$('body').on('focus', '[contenteditable]', function() {
    const $this = $(this);
    $this.data('before', $this.text());
    return $this;
}).on('blur keyup paste input', '[contenteditable]', function() {
    const $this = $(this);
    if ($this.data('before') !== $this.text()) {
        $this.data('before', $this.text());
        $this.trigger('change');
    }
});

$('[contenteditable]').on('change', function(){
     //looks like I changed.
     parseContentEditorAndFindImages( $(this) );

});

function parseContentEditorAndFindImages( $elem ){

     var rawHtml = $elem.text();
     currentImages  = [];
     html = $.parseHTML( rawHtml );
     $.each( html, function( i, el ) {
           //parse html here and detect images

     });
}

<div id="myEditor" contenteditable="true"  /">
var currentImages=[];
$('body')。在('focus','contenteditable',函数()上{
const$this=$(this);
$this.data('before',$this.text());
退还$this;
}).on('blur keyup paste input','[contenteditable]',function(){
const$this=$(this);
if($this.data('before')!==$this.text()){
$this.data('before',$this.text());
$this.trigger('change');
}
});
$(“[contenteditable]”)。在('change',function()上{
//看起来我变了。
ParseContentEditor和FindImage($(this));
});
函数parseContentEditorAndFindImages($elem){
var rawHtml=$elem.text();
currentImages=[];
html=$.parseHTML(rawHtml);
$.each(html、函数(i、el){
//在此处解析html并检测图像
});
}

我在这里看到的唯一选择是保留原始内容的副本,并将其与新内容进行比较。如果删除了链接,请删除链接的图像。如果看不到更多的编辑器代码,很难说,但一旦编辑器文本框中不再有图像标记,您可以在编辑器文本框中侦听事件,然后删除。我想在这里冒险一下,我猜你使用的是一个可编辑内容的Div?是的,我使用Div@SquiggsIs可能提供更多的代码信息取决于文本体是否包含html标记,尝试检查文本体是否包含str_('c6bc9b4b0ae0244058a4181f8e84007d-1.jpg'),然后删除图像