0

我从父应用程序打开了一个子浏览器窗口 (aspx)。子窗口有一些控件和一个文本框。当用户完成后,他/她单击一个按钮,以下代码从子窗口中获取值并填充父窗口,如下所示:

window.opener.document.form1.InputContainer$LetterInput$txtReasons.value = txtVal;

这对于我在父页面上的文本框非常有用。但是现在,我需要填充一个列表框并且运气不佳。我已经尝试了这两种方法,但无济于事:

o.text = txtVal;
o.value = "1";
window.opener.document.form1.InputContainer$LetterInput$lstReasons.add(o);

window.opener.document.form1.InputContainer$LetterInput$lstReasons.add("Text", "Value");

两者都得到“htmlfile:不支持此类接口”。

有人有什么想法吗?

谢谢,

杰森

4

2 回答 2

0
var newOption = document.createElement('option');
newOption.value = textbox.value; // The value that this option will have
newOption.innerHTML = textbox.value; // The displayed text inside of the <option> tags

// Finally, add the new option to the listbox
window.opener.document.form1.InputContainer$LetterInput$lstReasons.appendChild(newOption);
于 2011-07-20T17:02:24.940 回答
0

好的,进行了一些修改,但找到了解决方案!

首先,在父 aspx 中创建一个函数,如下所示:

function NewOption(newVal)
{
//alert("The entry is: " + newVal);
var sel = document.getElementById("<%= MyListbox.clientID %>");
sel.options[sel.options.length]=new Option(newVal, newVal, true, true);    
}

然后,从子页面调用该函数,如下所示:

function SendValues()
{
var txtVal = document.form1.txtReasons.value;
var sel = window.opener.NewOption(txtVal);
}

仍然有一两个扭结(它只传递文本,而不是值),但它可以通过添加额外的参数轻松修复......

希望外面的其他人可以使用它!

于 2011-07-20T18:28:34.870 回答