jhtmlarea所见即所得编辑器-添加表 [英] jhtmlarea wysiwyg editor - Adding Table

查看:103
本文介绍了jhtmlarea所见即所得编辑器-添加表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经进行了广泛的搜索,以查找有关添加自定义工具栏按钮的信息,该按钮会将表格插入编辑器.

I've done extensive searches looking for info on adding a custom toolbar button that would insert a table into the editor.

这就是我能找到的全部(顺便说一句,它并没有回答问题): 在jHtmlArea中添加表

This is all I could find (which, btw doesn't answer the question): Adding tables in jHtmlArea

任何人都对如何做有任何想法,或者看过类似的东西可以用作参考?

Anyone have any thoughts on how to do or have seen something similar that I could use as reference?

谢谢 乔

推荐答案

对不起,我想复活一个旧话题,但是我也希望能够使用jhtmlarea添加表.这就是我想出的

Sorry to revive an old topic, but I also wanted to be able to add tables using jhtmlarea. This is what I came up with

$("#editor").htmlarea({
    toolbar: [
        ["html"],
        ["bold","italic","underline","strikeThrough","|","subscript","superscript"],
        ["orderedList","unorderedList"],
        ["indent","outdent"],
        ["link","unlink","|","horizontalrule"],
        ["cut","copy","paste"],
        [{
            css: 'jhtml-table',
            text: 'Insert Table',
            action: function(btn) {
                var t = this, li = btn.closest('li');
                var trtd = Array(11).join('<tr>'+Array(11).join('<td></td>')+'</tr>');
                var tbl = $('<table tabindex="0"><tbody>' + trtd + '</tbody><tfoot><tr><td colspan="10" style="color:#888;text-align:center;">&nbsp;</td></tr></tfoot></table>')
                    .css({position:'absolute', background:'#fff', border:'#bbb 1px solid', outline:'0 none'})
                    .appendTo(li)
                    .focus().blur(function(e){ tbl.remove(); });
                tbl.find('tbody td').css({border:'#bbb 1px solid',height:'12px',width:'12px'})
                    .hover(function(e){
                        var td = $(this),
                            x = td.index()+1,
                            y = td.closest('tr').index()+1;
                        tbl.find('tfoot td').html(x + 'x' + y);
                        tbl.find('tbody tr').slice(0,y).each(function(i){
                            $(this).find('td').slice(0,x).css({background:'#ddd'});
                            $(this).find('td').slice(x).css({background:'none'});
                        });
                        tbl.find('tbody tr').slice(y).each(function(i){
                            $(this).find('td').css({background:'none'});
                        })
                    })
                    .click(function(e){
                        var td = $(this),
                            x = td.index()+2,
                            y = td.closest('tr').index()+2;
                        t.pasteHTML('<table class="display-table"><tbody>' + Array(y).join('<tr>'+Array(x).join('<td>&nbsp;</td>')+'</tr>') + '</tbody></table>');
                        tbl.remove();
                    });

            }
        }]
    ],
    css: "css/jHtmlArea.editor.css"
});

我还没有进行任何跨浏览器测试(它在Chrome中运行),这很简单,但是它提供了一种快速的方法来放入html表.

I haven't done any cross-browser testing (it works in Chrome), and it's pretty simple, but it gives a quick way to drop in an html table.

这篇关于jhtmlarea所见即所得编辑器-添加表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆