0) { var converter = new M-6ren">
gpt4 book ai didi

javascript - 如何在一页中使用多个 pagedown?

转载 作者:行者123 更新时间:2023-11-29 21:54:21 25 4
gpt4 key购买 nike

我为此尝试了下面的代码,但它仅将向下翻页按钮添加到第一个 .wmd-input

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

最佳答案

看来我必须为 wmd 的每个元素添加唯一 ID。我的意思是 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;
});
}

关于javascript - 如何在一页中使用多个 pagedown?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27249462/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com