2011-05-20 59 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 
})