2011-05-20 27 views
0

我有一些问题与此代码?这里是我的代码创建从区域HtmlBox set_text函数什么都不做

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

它的创建编辑的文本编辑器,这一切都OK,但...在某些时刻,我必须把文本编辑器重新编辑的文本,我使用此功能。 ..

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”功能运输发射车什么都不做,警告我的数据存在,它是在正确的形式和所有,但缺少的东西....任何想法????

------------而第二个问题?在这个版本中,或者只是在我的代码,加粗按钮第一次确实不错,但如果我按它的文本恢复正常,它什么都不做,actualy它集多了一个对周围文本<b></b>标签(它是在HTML预览中所示) ..在HtmlBox插件的代码中,我可以修复此功能....任何一个? TNX ..

回答

0

set_text被suposed是一个全球性的功能? 我不能说它定义和htmlbox插件使用 很好的封装,所以我不认为它有全局功能。

也许set_text是盒子的方法????? like

box.set_text(data.content); 

其中是从set_text函数?从jQuery函数

+0

是的,这是暗示,就在我看到这个答案之前,试过了,它的工作.... :) – Nenad 2011-05-20 09:00:08

+0

框被创建为像HtmlBox的textarea对象,'set_ text()'是HtmlBox插件的函数,并且获得该函数的方法已经超过''.'就像你说的那样''box.set_text(data.content)'.....谢谢你... – Nenad 2011-05-20 09:03:13

+0

现在来图了解如何编辑粗体按钮?理念?? – Nenad 2011-05-20 09:13:06

0

存储对象回报这样的:

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