【问题标题】:HtmlBox set_text function does nothingHtmlBox set_text 函数什么都不做
【发布时间】:2011-05-20 06:58:09
【问题描述】:

我对这段代码有一些问题?这是我从区域创建文本编辑器的代码

var box;
...

box = jQuery("#text_vesti").htmlbox({
    toolbars:[
            [
                // Cut, Copy, Paste
                "cut","copy","paste",
                // Undo, Redo
                "undo","redo",
                // Bold, Italic, Underline,
                "bold","italic","underline"
            ],
            [
                // Left, Right, Center, Justify
                "justify","left","center","right",
                // Ordered List, Unordered List
                "ol","ul",
                // Hyperlink, Remove Hyperlink, Image
                "link","unlink","image"

            ],
            [// Show code
                "code",
                // Formats, Font size, Font family, Font color, Font, Background
                "fontsize","fontfamily",
            ],
        ],
        skin:"silver",
        icons:"silk"
}); 

它是创建编辑器,一切正常,但是...在某些时候我必须将文本放入编辑器以重新编辑文本,我使用此功能...

    function editujOvo (id){
        editovanje = true;
        id_za_editovanje = id;


        jQuery("#r" + pom).css({"background":"none"});
        jQuery("#r" + id).css({"background":"#dfdfdf"});
        pom = id;

        var podaci = "br=3&id=" + id;
       // alert(podaci);

        jQuery.post("ajax_exe.php", podaci,function(data){
            //alert(data.id);
           // alert(data.naslov);
            alert(data.content);
            document.getElementById("naslov_vesti").value = data.naslov;
            //document.getElementById("text_vesti").value = data.content;
            box=set_text(data.content);
            document.getElementById("date").value = data.datum;

          window.frames["news_page"].location.reload();
        },'json');            
    }

但它什么也没做,就在“set_text”函数告诉我数据存在并且它的格式正确且所有内容之前发出警报,但是缺少一些东西....有什么想法吗????

------------ 第二个问题?在这个版本中,或者只是在我的代码中,粗体按钮第一次没问题,但是如果我按下它以使文本恢复正常,它什么也不做,实际上它在文本周围设置了一对 <b></b> 标签(它显示在 html预览)..在HtmlBox插件的代码中我可以修复这个功能....任何一个???? tnx..

【问题讨论】:

    标签: html json jquery-plugins jquery


    【解决方案1】:

    set_text 应该是一个全局函数? 我无法定义它并且 htmlbox 插件使用 很好的封装,所以我不认为它具有全局功能。

    也许 set_text 是盒子的一种方法?????? 喜欢

    box.set_text(data.content);
    

    set_text 函数来自哪里??

    【讨论】:

    • 是的,这就是提示,就在我看到这个答案之前,尝试过它并且它有效.... :)
    • box 是用 HtmlBox 像 textarea 的对象一样创建的,set_text() 是 HtmlBox 插件的功能,获得该功能的方法已经结束 . 就像你说的 box.set_text(data.content).....谢谢...
    【解决方案2】:

    像这样存储从 jQuery 函数返回的对象:

    textbox = $('#texteditor').htmlbox({
    toolbars:{...}
    })
    // don't do that:
    function YourClass(){}
    YourClass.prototype = {}
    YourClass.prototype.set_htmlbox = function(){
      this.hb = $('#texteditor').htmlbox({
        toolbars:{...}
      })
    }
    
    // because you can't in future use this field to Ajax.
    
    var save = {
      icon: 'some.png',
      tooltip: 'Save',
      command: function(){
        // context of this function is window!!!
        // DON'T! IT'S INCORRECT!!!
        // this.hb.get_text()
        // this.post("/save")
        // this.get("/text/1")
      }
    }
    this.hb = $('#texteditor').htmlbox({
      toolbars:{...,save}
    })
    

    但你可以这样做:

    ...
    var save = {
      icon: 'some.png',
      tooltip: 'Save',
      command: function(){
        YourClass.hb.get_text()
        YourClass.post("/save")
        YourClass.get("/text/1")
      }
    }
    YourClass.hb = $('#texteditor').htmlbox({
      toolbars:{...,save}
    })
    

    或者这样

    ...
    var toolname = 'Save'
    var save = {
      icon: 'some.png',
      tooltip: toolname,
      command: function(){
      }
    }
    this.hb = $('#texteditor').htmlbox({
      toolbars:{...,save}
    })
    var _this = this  // Save context
    this.hb.find('input[title='+toolname+']').unbind('click').bind('bind',function(){
      _this // <- use context
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-11
      • 1970-01-01
      • 2012-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多