Javascript execCommand insertHtml,未插入外部div为什么?
为什么不插入DIV,而只插入IMGJavascript execCommand insertHtml,未插入外部div为什么?,javascript,Javascript,为什么不插入DIV,而只插入IMG $(document).ready(function() { $(document).on('click', '#insertImage', function(){ /* Why is the DIV not inserted ? */ var item = "<div class='resizable'><img src='http://www.rockiesve
$(document).ready(function() {
$(document).on('click', '#insertImage', function(){
/*
Why is the DIV not inserted ?
*/
var item = "<div class='resizable'><img src='http://www.rockiesventureclub.org/wp-content/uploads/2013/02/flower-icon.png'></div>";
document.execCommand('insertHTML', false,item);
})
});
$(文档).ready(函数(){
$(文档)。在('单击','插入图像',函数()上){
/*
为什么不插入DIV?
*/
var项目=”;
document.execCommand('insertHTML',false,item);
})
});
见:
既然已经在使用jQuery,为什么不使用它呢
var_$div=$(''),
_$img=$(“”);
_$div.append($img);
$('body')。追加($div);
问题的背景如下:
我只是希望能够使添加的图像向左或向右浮动。
由于jQueryUI会自动在每个可调整大小的项目周围添加一个包装器div,我认为我需要手动添加它,以便为其分配一个id
Freenode上的doug65536帮助我创建了此解决方案,而无需手动创建额外的div:
我们还发现小提琴在狩猎中不能正常工作
$(document).on('click', '#insertImage', function () {
document.execCommand('insertHTML', false,
"<img class='resizeable' id='myImg' src='http://imperavi.com/img/library.jpg'>");
$(".resizeable").resizable({
aspectRatio: true
}); //just a try here
$('#myImg').parent().css({
'float':'left',
'margin':'15px'
});
})
$(文档)。在('click','#insertImage',函数(){
document.execCommand('insertHTML',false,
"");
$(“.resizeable”).resizeable({
方面:正确
})试试看
$('#myImg').parent().css({
“float”:“left”,
“边距”:“15px”
});
})
多谢各位 如何将当前光标处的图像添加到内容可编辑div中?您使用的浏览器是什么?当我在Chrome中使用inspector时,我可以看到小提琴中添加了div()。
$(document).on('click', '#insertImage', function () {
document.execCommand('insertHTML', false,
"<img class='resizeable' id='myImg' src='http://imperavi.com/img/library.jpg'>");
$(".resizeable").resizable({
aspectRatio: true
}); //just a try here
$('#myImg').parent().css({
'float':'left',
'margin':'15px'
});
})