HtmlBox set_text 函数不执行任何操作

发布于 2024-11-08 22:45:23 字数 2064 浏览 0 评论 0原文

我对这段代码有一些问题吗?这是我的代码,

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”函数之前发出警报告诉我数据存在并且格式正确,但缺少某些内容......有什么想法吗???

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

I have some problems with this code? Here is my code that creates text editor from area

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"
}); 

it's create editor and it's all ok, but...in some moment I have to put text in editor to re-edit text and I use this function...

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

but it does nothing, alert just before "set_text" function tels me that data exists and it is in right form and all, but something is missing.... any ideas????

------------ And second question? in this version, or just in mine code, bold button first time does ok, but if I press it to return text to normal, it does nothing, actualy it sets one more pair of <b></b> tags around text (it's shown in html preview).. where in code of HtmlBox plugin I can repair this function.... any one???? tnx..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

断爱 2024-11-15 22:45:23

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

也许 set_text 是盒子的一个方法???
就像

box.set_text(data.content);

set_text 函数来自哪里?

set_text is suposed to be a global function?
i cant se it defined and the htmlbox plugin uses
nice encapsulation so i dont se it having global functions.

maybe the set_text is a method of the box?????
like

box.set_text(data.content);

where is the set_text function from??

岁月苍老的讽刺 2024-11-15 22:45:23

存储从 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
})

Store object return from jQuery function like that:

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}
})

But you may do like that:

...
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}
})

Or like that

...
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
})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文