我有一个函数可以从 xul 文件(比如说 tree.xul)中获取所选复选框的值。在另一个 XUL 文件中有一个文本框,我想在其中传递所选复选框的值(标签值)(比如说 textbox.xul)。
最初我是从“textbox.xul”文件打开“tree.xul”文件。当我选择复选框值并单击按钮将值传递到另一个 xul 文件(“textbox.xul”)时。
我在“textbox.xul”文件中有一个文本框,我想将复选框的值传递给该文本框。
<textbox id="ali" value=""/>
<button label="Contacts" onclick="DisplayContacts();"/>
在我的脚本中,我尝试这样做,但它不起作用,而且我还包含了这一小段代码函数
window.close();
传递值后关闭窗口(“tree.xul”)。
我必须使用数组来存储变量的所有值吗?
我正在尝试使用 Mozilla 对话框中的解释,但它不起作用。
function get() { // check the alignment on a number of cells in a table.
var table = document.getElementById("box");
var cells = table.getElementsByTagName("checkbox");
for (var i = 0; i < cells.length; i++)
{
var cell = cells[i];
if(cell.checked) {
alert(cell.getAttribute("label"));
var x = cell.getAttribute("label");
x = window.arguments[0];
// or cell.label
}
}
window.close();
}
这是动态创建的复选框值的代码:
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('style', 'color: green;');
var existing = document.getElementById('box');
var checkbox = document.createElement('checkbox');
capt.appendChild(checkbox);
checkbox.setAttribute('label', yyahoo);
checkbox.setAttribute('style', 'color: green;');
}
}
return arr;
}
在这里,用户选择“tree.xul”文件中的复选框,我有按钮(“function get()”)将值添加到“texbox.xul”窗口中的文本框。
这是从 text-box.xul 文件中打开 tree.xul 的函数:
function DisplayContacts()
{
var returnValues = { out: null };
window.openDialog("chrome://hello/content/sundayevening2.xul","sundayevening2","", returnValues);
}
请帮助我将值传递到另一个 XUL 窗口中的文本框。
谢谢你。
最佳答案
您可能想要使用这样的内容:Passing extra parameters to the dialog in XUL
这提供了一种在 xul 文件之间传递值的简单方法。
对于您的问题,您可以在 textbox.xul 中执行类似的操作。这将打开tree.xul以及额外的参数returnValues:
var returnValues = { out: null };
window.openDialog("tree.xul", "tree", "modal", returnValues);
注意modal
是必须的。
接下来在您的tree.xul中,存储您想要传递给textbox.xul的所有值(我们称之为x),如下所示:
window.arguments[0].out = x
注意 window.argument[0] 指的是 returnValues
现在您可以访问 textbox.xul 中的 x 值(这是您案例中的标签名称),如下所示:
var labels = returnValues.out;
基本上,
在打开子窗口时将参数传递给子窗口。
然后在子窗口中,用希望传回的值填充参数 父窗口,然后关闭子窗口。
现在回到父窗口,您可以访问传递给子窗口的参数,它包含子窗口更新的信息。
关于javascript - 使用 JavaScript 将变量值从子 XUL 窗口传递到父 XUL 窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7172333/