I tried the below code for that, but it adds pagedown buttons to only the first .wmd-input
.
我尝试了下面的代码,但它只向第一个.wmd输入添加了向下翻页按钮。
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;
});
}
1 个解决方案
#1
2
Looks like i have to add unique ID for each element of wmd. I mean wmd-input
, wmd-preview
and wmd-button-bar
. I modified this id attributes programmatically. This can be done with modifying manually but my length of inputs are dynamic.
看起来我必须为wmd的每个元素添加唯一ID。我的意思是wmd-input,wmd-preview和wmd-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);
So when this ID attributes is set, i called the editor with postfix variable and problem solved.
因此,当设置此ID属性时,我使用postfix变量调用编辑器并解决问题。
editors[i] = new Markdown.Editor(converters[i], i, options);
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;
});
}
#1
2
Looks like i have to add unique ID for each element of wmd. I mean wmd-input
, wmd-preview
and wmd-button-bar
. I modified this id attributes programmatically. This can be done with modifying manually but my length of inputs are dynamic.
看起来我必须为wmd的每个元素添加唯一ID。我的意思是wmd-input,wmd-preview和wmd-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);
So when this ID attributes is set, i called the editor with postfix variable and problem solved.
因此,当设置此ID属性时,我使用postfix变量调用编辑器并解决问题。
editors[i] = new Markdown.Editor(converters[i], i, options);
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;
});
}