2011-03-27 38 views
0
function EditorDivOpen(a){ 
    $('#'+a).show(); 
} 

function EditorDivClose(a){ 
    $('#'+a).close(); 
} 

function EditorDivFill(a,b){ 
    var init; 
    if(a == 'smileys'){ 
     init = '<img src="data/img/smileys/sad.png" onclick="EditorTextFill(\':(\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/happy.gif" onclick="EditorTextFill(\':)\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/angelnot.gif" onclick="EditorTextFill(\'0:=)\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/angry.gif" onclick="EditorTextFill(\'=(\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/blush.gif" onclick="EditorTextFill(\':@\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/cencored.png" onclick="EditorTextFill(\':*\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/confused.gif" onclick="EditorTextFill(\':?\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/cry.png" onclick="EditorTextFill(\';(\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/grin.gif" onclick="EditorTextFill(\':D\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/hmm.png" onclick="EditorTextFill(\':|\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/hypocrite.gif" onclick="EditorTextFill(\'0=)\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/lock.gif" onclick="EditorTextFill(\':x:\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/love.gif" onclick="EditorTextFill(\':3\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/sunglasses.gif" onclick="EditorTextFill(\'8)\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/shifty.gif" onclick="EditorTextFill(\'|)\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/shock.gif" onclick="EditorTextFill(\'O_o\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/shock.gif" onclick="EditorTextFill(\':o\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/sweatingbullets.gif" onclick="EditorTextFill(\'^_^\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/tongue.gif" onclick="EditorTextFill(\':p\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/tongue.gif" onclick="EditorTextFill(\':P\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/wink.gif" onclick="EditorTextFill(\';)\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/wry.gif" onclick="EditorTextFill(\'xo\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/wry.gif" onclick="EditorTextFill(\'XD\');" class="point" alt="smiley"> \ 
       <img src="data/img/smileys/wry.gif" onclick="EditorTextFill(\'xD\');" class="point" alt="smiley">'; 
    } 
    else 
    { 
     init = '<img src="data/img/buttons/bold.png" onclick="EditorTextFill(\'[b][/b]\');" class="point" alt="bold"> \ 
       <img src="data/img/buttons/italic.png" onclick="EditorTextFill(\'[i][/i]\');" class="point" alt="italic"> \ 
       <img src="data/img/buttons/underline.png" onclick="EditorTextFill(\'[u][/u]\');" class="point" alt="underline"> \ 
       <img src="data/img/buttons/strike.png" onclick="EditorTextFill(\'[s][/s]\');" class="point" alt="strike"> \ 
       <img src="data/img/buttons/link.png" onclick="EditorTextFill(\'[url][/url]\');" class="point" alt="Link"> \ 
       <img src="data/img/buttons/image.png" onclick="EditorTextFill(\'[img][/img]\');" class="point" alt="Image">'; 
    } 

    init = '<img src="data/img/buttons/remove.png" alt="remove" class="closebutton point" onclick="EditorDivClose(\'edit-content\');">'+ init; 

    $('#'+b).html(init); 
} 

function EditorTextFill(msg){ 
    $('#editor-textarea').html() = $('#editor-textarea').html() + msg; 
} 

      <img src="data/img/smileys/happy.gif" alt="smileys" onclick="EditorDivOpen('edit-content'); EditorDivFill('smileys', 'edit-content');" class="point"> 
      <img src="data/img/buttons/bold.png" alt="tags" onclick="EditorDivOpen('edit-content'); EditorDivFill('tags', 'edit-content');" class="point"> 
      <div id="edit-content"> 
      </div> 

      <textarea cols="60" rows="6" name="message" id="editor-textarea"></textarea><br> 
      <input type="submit" value=" submit "> 

我的一些功能在上面的代碼將無法正常工作,這些都是EditorDivClose()EditorTextFill()。在這兩個我得到的錯誤:股利不會關閉和文字不放在textarea的

this property or method is not supported by this object

由兩個在第一個$字符。

回答

2

沒有名爲close的jQuery方法。您需要hide

function EditorDivClose(a){ 
    $('#'+a).hide(); 
} 

設置HTML值,你傳遞你想要設置爲html方法的價值,像這樣

function EditorTextFill(msg){ 
    var oldVal = $('#editor-textarea').html(); 
    $('#editor-textarea').html(oldVal + msg); 
} 

function EditorTextFill(msg){ 
    $('#editor-textarea').html(function (i, oldVal) { 
     return oldVal + msg 
    }); 
} 

看了一些文檔在jQuery documentation website或jqapi.com。它有助於。

+0

關閉/隱藏是一個錯誤。 *羞恥*, 但是,雖然感謝;) – Thew 2011-03-27 13:22:27