bootstrap-wysiwyg中JS控件富文本的用法

1、引入js和css文件(注:这里必须引入正确,下面是我的路径,你修改为你自己的,不多说了)

<link href="/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
<link href="ont-awesome.css" rel="stylesheet">
<script src="{$url_admin}assets/js/jquery.min.js"></script>
<script src="{$url_admin}assets/js/ace-extra.min.js"></script>
<script src="{$url_admin}assets/js/jquery-ui-1.10.3.custom.min.js"></script>
<script src="{$url_admin}assets/js/jquery.ui.touch-punch.min.js"></script>
<script src="{$url_admin}assets/js/markdown/markdown.min.js"></script>
<script src="{$url_admin}assets/js/markdown/bootstrap-markdown.min.js"></script>
<script src="{$url_admin}assets/js/jquery.hotkeys.min.js"></script>
<script src="{$url_admin}assets/js/uncompressed/bootstrap-wysiwyg.js"></script>
<script src="{$url_admin}assets/js/bootbox.min.js"></script>
<script src="{$url_admin}assets/js/ace-elements.min.js"></script>

2、其实调用也很容易,难点在于怎么把‘富文本里面的内容提交给后台’(这里我给到一个隐藏input  如下面的代码)

<!-- 这里是html代码-->

<form  action="" class="form-group" id="addNews">
                <div class="wysiwyg-editor" id="editor1" name="editor1">


                </div>

                <input type='hidden' name='details' id='details' value=''>

                <button  οnclick="copyNewsHidden()" >提交</button>

</form>


//js调用富文本如下


<script type="text/javascript">
            jQuery(function($){

                function showErrorAlert (reason, detail) {
                    var msg='';
                    if (reason==='unsupported-file-type') { msg = "Unsupported format " +detail; }
                    else {
                        console.log("error uploading file", reason, detail);
                    }
                    $('<div class="alert"> <button type="button" class="close" data-dismiss="alert">&times;</button>'+
                            '<strong>File upload error</strong> '+msg+' </div>').prependTo('#alerts');
                }
                $('#editor1').ace_wysiwyg({
                    toolbar:
                            [
                                'font',
                                null,
                                'fontSize',
                                null,
                                {name:'bold', className:'btn-info'},
                                {name:'italic', className:'btn-info'},
                                {name:'strikethrough', className:'btn-info'},
                                {name:'underline', className:'btn-info'},
                                null,
                                {name:'insertunorderedlist', className:'btn-success'},
                                {name:'insertorderedlist', className:'btn-success'},
                                {name:'outdent', className:'btn-purple'},
                                {name:'indent', className:'btn-purple'},
                                null,
                                {name:'justifyleft', className:'btn-primary'},
                                {name:'justifycenter', className:'btn-primary'},
                                {name:'justifyright', className:'btn-primary'},
                                {name:'justifyfull', className:'btn-inverse'},
                                null,
                                {name:'createLink', className:'btn-pink'},
                                {name:'unlink', className:'btn-pink'},
                                null,
                                {name:'insertImage', className:'btn-success'},
                                null,
                                'foreColor',
                                null,
                                {name:'undo', className:'btn-grey'},
                                {name:'redo', className:'btn-grey'}
                            ],
                    'wysiwyg': {
                        fileUploadError: showErrorAlert
                    }
                }).prev().addClass('wysiwyg-style2');

                $('[data-toggle="buttons"] .btn').on('click', function(e){
                    var target = $(this).find('input[type=radio]');
                    var which = parseIrnt(target.val());
                    var toolbar = $('#editor1').prev().get(0);
                    if(which == 1 || which == 2 || which == 3) {
                        toolbar.className = toolbar.className.replace(/wysiwyg\-style(1|2)/g , '');
                        if(which == 1) $(toolbar).addClass('wysiwyg-style1');
                        else if(which == 2) $(toolbar).addClass('wysiwyg-style2');
                    }
                });




                //Add Image Resize Functionality to Chrome and Safari
                //webkit browsers don't have image resize functionality when content is editable
                //so let's add something using jQuery UI resizable
                //another option would be opening a dialog for user to enter dimensions.
                if ( typeof jQuery.ui !== 'undefined' && /applewebkit/.test(navigator.userAgent.toLowerCase()) ) {

                    var lastResizableImg = null;
                    function destroyResizable() {
                        if(lastResizableImg == null) return;
                        lastResizableImg.resizable( "destroy" );
                        lastResizableImg.removeData('resizable');
                        lastResizableImg = null;
                    }

                    var enableImageResize = function() {
                        $('.wysiwyg-editor')
                                .on('mousedown', function(e) {
                                    var target = $(e.target);
                                    if( e.target instanceof HTMLImageElement ) {
                                        if( !target.data('resizable') ) {
                                            target.resizable({
                                                aspectRatio: e.target.width / e.target.height
                                            });
                                            target.data('resizable', true);

                                            if( lastResizableImg != null ) {//disable previous resizable image
                                                lastResizableImg.resizable( "destroy" );
                                                lastResizableImg.removeData('resizable');
                                            }
                                            lastResizableImg = target;
                                        }
                                    }
                                })
                                .on('click', function(e) {
                                    if( lastResizableImg != null && !(e.target instanceof HTMLImageElement) ) {
                                        destroyResizable();
                                    }
                                })
                                .on('keydown', function() {
                                    destroyResizable();
                                });
                    }

                    enableImageResize();

                    /**
                     //or we can load the jQuery UI dynamically only if needed
                     if (typeof jQuery.ui !== 'undefined') enableImageResize();
                     else {//load jQuery UI if not loaded
            $.getScript($path_assets+"/js/jquery-ui-1.10.3.custom.min.js", function(data, textStatus, jqxhr) {
                if('ontouchend' in document) {//also load touch-punch for touch devices
                    $.getScript($path_assets+"/js/jquery.ui.touch-punch.min.js", function(data, textStatus, jqxhr) {
                        enableImageResize();
                    });
                } else  enableImageResize();
            });
        }
                     */
                }


            });

</script>

3、利用隐藏域把富文本的内容提交给后台(这里我给到一个提交的js方法copyNewsHidden()如下)

<script>
function copyNewsHidden(){
    var  newsEditor1=$('#editor1').html();
    var details=$('#details').val(newsEditor1);

    $('#addNews').submit();
}

</script>

4、下篇写下如何把本地图片上传到服务器上面


PHP+Mysql网站源码学习请访问:PHP+Mysql网站源码学习请访问

http://www.erdangjiade.com/

转载于:https://www.cnblogs.com/66daima/p/7507708.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很全面的Ace Admin1.3官方文档,包含有最全面的组件及例子,适合急需使用该技术开发的人。 响应式Bootstrap网站后台管理系统模板ace admin,非常不错的轻量级易用的admin后台管理系统,基于Bootstrap3,拥有强大的功能组件以及UI组件,基本能满足后台管理系统的需求,而且能根据不同设备适配显示,而且还有四个主题可以切换。 网页图标全采用FontAwesome,除Bootstrap,jQuery UI使用到的第三方插件有: jQuery 2.0.3 jQuery UI 1.10.3 (Custom Build) Twitter Bootstrap 3.0.0 FontAwesome 3.2.1 Google "Open Sans" Font jQuery Flot Charts 0.8.1 jQuery Sparklines 2.1.2 Easy Pie Chart 1.2.5 jQuery Knob 1.2.0 jQuery Validate 1.11.1 FuelUX 2.3.0 (Spinner & Wizard & Treeview) FullCalendar 1.6.4 jQuery ColorBox 1.4.27 jQuery dataTables 1.9.4 jQuery Chosen 1.0 jQuery Masked Input 1.3.1 jQuery Input Limiter 1.3.1 jQuery AutoSize 1.17.7 Bootstrap Colorpicker Bootstrap Datepicker Bootstrap Timepicker v0.2.3 Bootstrap DateRange Picker 1.2 Bootbox.js 4.0.0 jQuery Gritter 1.7.4 jQuery slimScroll 1.1.1 Spin.js 1.3.0 jQuery UI Touch Punch 0.2.2 Google Code Prettify ExplorerCanvas Mindmup Wysiwyg Editor Toopay Markdown Editor 1.1.4 X-editable 1.4.6 Select2 3.4.2 Bootstrap Tags 2.2.5 jQuery Mobile 1.3.2 (Custom Build) jqGrid 4.5.2 Dropzone.js 3.0 Nestable lists plugin 浏览器兼容: Firefox 5+ Google Chrome 14+ Internet Explorer 8 Internet Explorer 9 Opera 11 Safari 5 Bootstrap兼容: Bootstrap 2.2.x Bootstrap 2.3.x Bootstrap 3.0.x ace admin

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值