首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nicEdit中的选择元素

nicEdit中的选择元素
EN

Stack Overflow用户
提问于 2012-09-19 16:18:15
回答 1查看 770关注 0票数 1

我正在开发一个nicEdit插件来上传图片以外的文件。为了做到这一点,我使用了nicUpload插件,并对其进行了调整。

正如您在下面的代码中所看到的,我首先插入一个图像,然后尝试将该图像包装在一个链接中,但是它没有工作。

如果删除//Insert the image部分,我可以包装选定的文本,但我希望创建图像,然后选择该图像作为要包装的文本。

//Insert the link节存在时,//Insert the image部分根本不工作。

代码语言:javascript
复制
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
            }); 
        }   
    }
EN

回答 1

Stack Overflow用户

发布于 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' }); } }

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12498813

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档