1

此代码(链接到操场:http ://tinyurl.com/6ed9dyv )

var label = new qx.ui.basic.Label('<input type="file" id="files" name="files[]"/>').set({width: 250, rich:true, wrap:true});

var doc = this.getRoot();
doc.setLayout(new qx.ui.layout.VBox(10));

doc.add(label);

var button1 = new qx.ui.form.Button("Test");
doc.add(button1);

button1.addListener("execute", function(e) {
  var obj = document.getElementById('files');
  if (obj)
    alert(obj.files.length);
});

对我不起作用。obj.files 始终未定义。奇怪的是,当我切换到另一个选项卡然后回到包含此代码的选项卡时,它确实在具有多个选项卡的应用程序中工作。

4

1 回答 1

2

我认为问题在于您以一种意想不到的方式添加 HTML 代码。我认为 qx 队列做了一些不像你的例子显示的那样工作的东西。我做了一个小例子来展示如何使用自己的小部件来完成:

qx.Class.define("my.Upload",
{
  extend : qx.ui.core.Widget,

  members :
  {
    _createContentElement : function()
    {
      return new qx.html.Element(
        "input",
        {
          overflowX: "hidden",
          overflowY: "hidden"
        },
        {
          type: "file"
        }
      );
    }, 

    getFiles : function() {
      return this.getContentElement().getDomElement().files;
    }
  }
});

var upload = new my.Upload();

var doc = this.getRoot();
doc.setLayout(new qx.ui.layout.VBox(10));

doc.add(upload);

var button1 = new qx.ui.form.Button("Test");
doc.add(button1);

button1.addListener("execute", function(e) {
  alert(upload.getFiles().length);
});

这里有一个运行游乐场示例的链接:http: //tinyurl.com/6xwxfq8

于 2011-10-11T11:09:10.350 回答