Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在一页中使用多页向下?_Javascript_Jquery_Pagedown - Fatal编程技术网

Javascript 如何在一页中使用多页向下?

Javascript 如何在一页中使用多页向下?,javascript,jquery,pagedown,Javascript,Jquery,Pagedown,我尝试了下面的代码,但它只在第一个.wmd输入中添加了pagedown按钮 if ($(".wmd-input").length > 0) { var converter = new Markdown.Converter(); var help = function () { alert("Do you need help?"); } var options = { helpButton: { handler: help }, str

我尝试了下面的代码,但它只在第一个
.wmd输入中添加了pagedown按钮

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输入
wmd预览
wmd按钮栏
。我以编程方式修改了这个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属性被设置时,我用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;
    });
 }