关键词:ueditor用editor.execCommand( 'insertimage'设置宽度时width不支持百分比,ueditor上传的图片设置宽度100%无效,ueditor上传的图片宽度只支持Number类型
正解:
ueditor.all.js设置如下:
搜索这段代码utils.each('width,height,border,hspace,vspace'
,位置在 11128
function unhtmlData(imgCi) {
utils.each('width,height,border,hspace,vspace'.split(','), function (item) {
if (imgCi[item]) {
// imgCi[item] = parseInt(imgCi[item], 10) || 0;
//改为如下:
imgCi[item] = imgCi[item] || 0;
}
});
utils.each('src,_src'.split(','), function (item) {
if (imgCi[item]) {
imgCi[item] = utils.unhtmlForUrl(imgCi[item]);
}
});
utils.each('title,alt'.split(','), function (item) {
if (imgCi[item]) {
imgCi[item] = utils.unhtml(imgCi[item]);
}
});
}
如注释所示:将parseInt(imgCi[item], 10)
改为imgCi[item]
,这样就支持px,rem,%等之类的单位了。
ueditor.all.min.js设置如下:
搜索这段代码UE.commands.insertimage
,当代码用webstorm格式化后,位置在3114
function c(a) {
utils.each("width,height,border,hspace,vspace".split(","), function (b) {
//a[b] && (a[b] = parseInt(a[b], 10) || 0)
a[b] && (a[b] = a[b] || 0)
}), utils.each("src,_src".split(","), function (b) {
a[b] && (a[b] = utils.unhtmlForUrl(a[b]))
}), utils.each("title,alt".split(","), function (b) {
a[b] && (a[b] = utils.unhtml(a[b]))
})
}
如注释所示:将a[b] && (a[b] = parseInt(a[b], 10) || 0)
改为a[b] && (a[b] = a[b] || 0)
,效果同上;