2014-12-02 40 views
2

我嘗試了下面的代碼,但它只是向第一個.wmd-input添加了pagedown按鈕。如何在一個頁面中使用多個pagedown?

enter image description here

if ($(".wmd-input").length > 0) { 
    var converter = new Markdown.Converter(); 
    var help = function() { alert("Do you need help?"); } 
    var options = { 
     helpButton: { handler: help }, 
     strings: {quoteexample: "whatever you're quoting, put it right here"} 
    }; 
    var editors = []; 
    var i = 0; 

    $(".wmd-input").each(function() { 
     editors[i] = new Markdown.Editor(converter, "", options); 
     editors[i].run(); 
     i = i + 1; 
    }); 
} 
+2

你應該把溶液作爲自己回答,然後接受它(而不是編輯的問題)。請參閱:http://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/ – Carpetsmoker 2014-12-02 15:27:39

+0

好的,我會這樣做的。 – kastelli 2014-12-02 15:50:10

回答

2

看起來像我必須添加唯一ID WMD的每個元素。我的意思是wmd-inputwmd-previewwmd-button-bar。我以編程方式修改了這個id屬性。這可以通過手動修改來完成,但我的輸入長度是動態的。

// make wmd's id's unique 
    var pBox = $(this).parents(".box"); 
    $(pBox).find("textarea").attr('id', "wmd-input" + i); 
    $(pBox).children("#wmd-preview").attr('id', "wmd-preview" + i); 
    $(pBox).find("#wmd-button-bar").attr('id', "wmd-button-bar" + i); 

因此,當這個ID屬性設置,我調用了編輯器後綴變量和問題解決。

editors[i] = new Markdown.Editor(converters[i], i, options); 

enter image description here

if ($(".wmd-input").length > 0) { 
    var converters = []; 
    var editors = []; 
    var i = 1; 
    $(".wmd-input").each(function() { 
     converters[i] = new Markdown.Converter(); 
     var help = function() { alert("Do you need help?"); } 
     var options = { 
     helpButton: { handler: help }, 
     strings: {quoteexample: "whatever you're quoting, put it right here"} 
     }; 

     // make wmd's id's unique 
     var pBox = $(this).parents(".box"); 
     $(pBox).find("textarea").attr('id', "wmd-input" + i); 
     $(pBox).children("#wmd-preview").attr('id', "wmd-preview" + i); 
     $(pBox).find("#wmd-button-bar").attr('id', "wmd-button-bar" + i); 

     editors[i] = new Markdown.Editor(converters[i], i, options); 
     editors[i].run(); 
     i = i + 1; 
    }); 
} 
相關問題