我正在开发一个nicEdit插件来上传图片以外的文件。为了做到这一点,我使用了nicUpload插件,并对其进行了调整。
正如您在下面的代码中所看到的,我首先插入一个图像,然后尝试将该图像包装在一个链接中,但是它没有工作。
如果删除//Insert the image部分,我可以包装选定的文本,但我希望创建图像,然后选择该图像作为要包装的文本。
当//Insert the link节存在时,//Insert the image部分根本不工作。
onUploaded:function(B){
this.removePane();
// Insert the image.
if(!this.im) {
var tmp = 'javascript:nicImTemp();';
this.ne.nicCommand("insertImage",tmp);
this.im = this.findElm('IMG','src',tmp);
}
if(this.im) {
this.im.setAttributes({
src : 'http://127.0.0.1/nicEditDev/src/nicFile/images/pdf.png',
alt : 'PDF'
});
}
// Insert the link wrapping the image.
console.log(this.im);
var url=B.links.original;
if(!this.ln) {
var tmp = 'javascript:nicTemp();';
this.ne.nicCommand("createlink",tmp);
this.ln = this.findElm('A','href',tmp);
}
if(this.ln) {
this.ln.setAttributes({
href : url,
title : 'PDF',
innerHTML : this.im
});
}
}发布于 2015-09-16 07:22:39
试试这个,它对我有用:
onUploaded: function(a) { this.removePane(); var c = a.url; if (this.im) { this.im || (this.ne.selectedInstance.restoreRng(), this.ne.nicCommand("insertImage", c), this.im = this.findElm("IMG", "src", c)); var b = parseInt(this.ne.selectedInstance.elm.getStyle("width")); this.im && this.im.setAttributes({ src: c, width: b && a.width ? Math.min(b, a.width) : "", alt: a.alt }) } else { this.ln || (this.ne.selectedInstance.restoreRng(), this.ne.nicCommand("createlink", c), this.ln = this.findElm('A', 'href', c)); this.ln && this.ln.setAttributes({ href: c, title: 'PDF' }); } }
https://stackoverflow.com/questions/12498813
复制相似问题