我正在尝试使用以下代码在运行时填充带有Vbox元素的Hbox元素:

XUL代码:

<hbox style="overflow:auto;" id="canvasContainer"> </hbox>

JavaScript代码:

  this.canvasContainer = document.getElementById("canvasContainer");
  for(var i = 0;i<k;i++){
    let imgCanvas = document.createElementNS("http://www.w3.org/1999/xhtml",'html:canvas');
    imgCanvas.setAttribute("width",200);
    imgCanvas.setAttribute("height",150);
    imgCanvas.getContext("2d").fillRect(0,0,200,150);   
    let canvasVbox = document.createElementNS("http://www.w3.org/1999/xhtml",'vbox');
    this.canvasContainer.appendChild(canvasVbox);

    let canvasLabel = document.createElement("label");
    canvasLabel.setAttribute("value",i);
    canvasLabel.setAttribute("flex",1);
    canvasVbox.setAttribute("flex",1);
    canvasVbox.appendChild(imgCanvas);
    canvasVbox.appendChild(canvasLabel);

    this.canvasContainer.appendChild(canvasVbox);
  }

这导致画布和标签在另一个下方垂直显示。你知道问题可能来自吗?难道是不可能动态填充盒子吗?是Xulrunner中的错误吗?您是否有不使用网格的可能解决方法的想法?

有帮助吗?

解决方案

问题是行:让CanvasvBox = document.CreateElementNS(“ http://www.w3.org/1999/xhtml”,'vbox');

Vbox不是XHTML的一部分,而是Xul语法的一部分,因此我只需要替换“ http://www.w3.org/1999/xhtml”,“ http://wwwww.mozilla.org/keymaster/gatekatekeeperer/在那里。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top