在 XUL 中使用 DOM JavaScript 动态创建复选框

发布于 2024-11-30 23:46:29 字数 1378 浏览 4 评论 0原文

我想在 XUL 中使用 DOM JavaScript 为树值动态创建复选框: 此函数用于获取我的 XUL 树的值:

function choose() {
  var tree = document.getElementById('myTodoListTree');
  for (var i = 0; i < tree.view.rowCount; i++) {
    if (tree.view.getCellValue(i, tree.columns.getColumnAt(0)) == 'true'){
      alert(
        tree.view.getCellText(i, tree.columns.getNamedColumn("name"))+"\n"+
        tree.view.getCellText(i, tree.columns.getNamedColumn("lastname"))+"\n"+
        tree.view.getCellText(i, tree.columns.getNamedColumn("gmail"))+"\n"+
        tree.view.getCellText(i, tree.columns.getNamedColumn("yahoo"))+"\n"+
        tree.view.getCellText(i, tree.columns.getNamedColumn("url"))+"\n"+
        tree.view.getCellText(i, tree.columns.getNamedColumn("facebook-id"))
      );
      var firstName= tree.view.getCellText(i, tree.columns.getNamedColumn("name"));
      var lastName= tree.view.getCellText(i, tree.columns.getNamedColumn("lastname"));
      var Gmail= tree.view.getCellText(i, tree.columns.getNamedColumn("gmail"));
      var Yahoo= tree.view.getCellText(i, tree.columns.getNamedColumn("yahoo"));
      var Facebook = tree.view.getCellText(i, tree.columns.getNamedColumn("url"));
      var FacebookId = tree.view.getCellText(i, tree.columns.getNamedColumn("facebook-id"));
    }
  }
  return arr;                   
} 

此 mybox,我想在此框中附加动态创建的组框复选框:

I want to create checkbox dynamically using DOM JavaScript in XUL for tree values:
This function is used to get the values of my XUL tree:

function choose() {
  var tree = document.getElementById('myTodoListTree');
  for (var i = 0; i < tree.view.rowCount; i++) {
    if (tree.view.getCellValue(i, tree.columns.getColumnAt(0)) == 'true'){
      alert(
        tree.view.getCellText(i, tree.columns.getNamedColumn("name"))+"\n"+
        tree.view.getCellText(i, tree.columns.getNamedColumn("lastname"))+"\n"+
        tree.view.getCellText(i, tree.columns.getNamedColumn("gmail"))+"\n"+
        tree.view.getCellText(i, tree.columns.getNamedColumn("yahoo"))+"\n"+
        tree.view.getCellText(i, tree.columns.getNamedColumn("url"))+"\n"+
        tree.view.getCellText(i, tree.columns.getNamedColumn("facebook-id"))
      );
      var firstName= tree.view.getCellText(i, tree.columns.getNamedColumn("name"));
      var lastName= tree.view.getCellText(i, tree.columns.getNamedColumn("lastname"));
      var Gmail= tree.view.getCellText(i, tree.columns.getNamedColumn("gmail"));
      var Yahoo= tree.view.getCellText(i, tree.columns.getNamedColumn("yahoo"));
      var Facebook = tree.view.getCellText(i, tree.columns.getNamedColumn("url"));
      var FacebookId = tree.view.getCellText(i, tree.columns.getNamedColumn("facebook-id"));
    }
  }
  return arr;                   
} 

This mybox, and I want to append the dynamically created groupbox check-boxes in this box:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ˇ宁静的妩媚 2024-12-07 23:46:29

最后,我学会了如何动态创建元素。

这就是解决方案:这里我动态创建了组框、标题和复选框。

function choose()
{
alert('hi');
  var tree = document.getElementById('myTodoListTree');
  for (var i = 0; i < tree.view.rowCount; i++) {
   if (tree.view.getCellValue(i, tree.columns.getColumnAt(0)) == 'true'){

var empty = " ";
var contact = (tree.view.getCellText(i, tree.columns.getNamedColumn("name"))+ empty+
tree.view.getCellText(i, tree.columns.getNamedColumn("lastname"))+ empty+ "Contacts:");

var ggmail = tree.view.getCellText(i, tree.columns.getNamedColumn("gmail"));
var yyahoo = tree.view.getCellText(i, tree.columns.getNamedColumn("yahoo"));

  var existingEl  = document.getElementById('box');
  var capt   = document.createElement('groupbox');
  existingEl.appendChild(capt);
  var captionEl   = document.createElement('caption');
  capt.appendChild(captionEl);
  captionEl.setAttribute('label', contact );
  captionEl.setAttribute('style', 'color: blue;');


  var existing  = document.getElementById('box');
  var checkbox   = document.createElement('checkbox');
  capt.appendChild(checkbox);
  checkbox.setAttribute('label', ggmail );
  checkbox.setAttribute("checked", "false")
  checkbox.setAttribute('style', 'color: green;');

  var existing  = document.getElementById('box');
  var checkbox   = document.createElement('checkbox');
  capt.appendChild(checkbox);
  checkbox.setAttribute('label', yyahoo);
checkbox.setAttribute("checked", "false")
  checkbox.setAttribute('style', 'color: green;');

    }
  }
  return arr;

} 

Finally, I have learnt how to create elements dynamically.

This is the solution: Here I have created group-box, caption and check-box dynamically.

function choose()
{
alert('hi');
  var tree = document.getElementById('myTodoListTree');
  for (var i = 0; i < tree.view.rowCount; i++) {
   if (tree.view.getCellValue(i, tree.columns.getColumnAt(0)) == 'true'){

var empty = " ";
var contact = (tree.view.getCellText(i, tree.columns.getNamedColumn("name"))+ empty+
tree.view.getCellText(i, tree.columns.getNamedColumn("lastname"))+ empty+ "Contacts:");

var ggmail = tree.view.getCellText(i, tree.columns.getNamedColumn("gmail"));
var yyahoo = tree.view.getCellText(i, tree.columns.getNamedColumn("yahoo"));

  var existingEl  = document.getElementById('box');
  var capt   = document.createElement('groupbox');
  existingEl.appendChild(capt);
  var captionEl   = document.createElement('caption');
  capt.appendChild(captionEl);
  captionEl.setAttribute('label', contact );
  captionEl.setAttribute('style', 'color: blue;');


  var existing  = document.getElementById('box');
  var checkbox   = document.createElement('checkbox');
  capt.appendChild(checkbox);
  checkbox.setAttribute('label', ggmail );
  checkbox.setAttribute("checked", "false")
  checkbox.setAttribute('style', 'color: green;');

  var existing  = document.getElementById('box');
  var checkbox   = document.createElement('checkbox');
  capt.appendChild(checkbox);
  checkbox.setAttribute('label', yyahoo);
checkbox.setAttribute("checked", "false")
  checkbox.setAttribute('style', 'color: green;');

    }
  }
  return arr;

} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文