Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript中将复选框值从父窗口移到弹出窗口中_Javascript_Html_Jsp_Popup - Fatal编程技术网

在javascript中将复选框值从父窗口移到弹出窗口中

在javascript中将复选框值从父窗口移到弹出窗口中,javascript,html,jsp,popup,Javascript,Html,Jsp,Popup,我试图将父JSP中填写的表单字段显示在弹出窗口中,以告知用户表单的填写量。 到目前为止,我只能显示文本字段值。我无法显示复选框值。下面是我编写的代码示例。我不知道为什么它不起作用 function loaded() { if(window.opener) { document.getElementById('tb').value = window.opener.document.getElementById("cb").outerHTML } } </scrip

我试图将父JSP中填写的表单字段显示在弹出窗口中,以告知用户表单的填写量。 到目前为止,我只能显示文本字段值。我无法显示复选框值。下面是我编写的代码示例。我不知道为什么它不起作用

function loaded() {
    if(window.opener) {
    document.getElementById('tb').value =   window.opener.document.getElementById("cb").outerHTML
    }
}
</script>
    <body onload="loaded()">
        <form>
            <input type=text id=tb>
       </form>
   </body>
   </html>
Parent.jsp

Name: <input type="text" id="name"/>
Gender: Male<input type="checkbox" name="gender" id="male"/>
        Female<input type="checkbox" name="gender" id="female"/>
<a href="PopUp.jsp" target="_blank">View</a>
function loaded() {
    if(window.opener) {
    document.getElementById('tb').value =   window.opener.document.getElementById("cb").outerHTML
    }
}
</script>
    <body onload="loaded()">
        <form>
            <input type=text id=tb>
       </form>
   </body>
   </html>
名称:
性别:男
女性
PopUp.jsp

<script>
function setThis(){
    document.getElementById("name").value=window.opener.document.getElementById("name").value;
    if(window.opener.document.getElementById("male").checked)
        document.getElementById("male").checked=true;
    if(window.opener.document.getElementById("female").checked)
        document.getElementById("female").checked=true;
}

</script>
<body onload="setThis();">
Name: <input type="text" id="name"/>
 Gender: Male<input type="checkbox" name="gender" id="male"/>
        Female<input type="checkbox" name="gender" id="female"/>
</body>
function loaded() {
    if(window.opener) {
    document.getElementById('tb').value =   window.opener.document.getElementById("cb").outerHTML
    }
}
</script>
    <body onload="loaded()">
        <form>
            <input type=text id=tb>
       </form>
   </body>
   </html>

函数setThis(){
document.getElementById(“名称”).value=window.opener.document.getElementById(“名称”).value;
if(window.opener.document.getElementById(“男性”).checked)
document.getElementById(“男性”).checked=true;
if(window.opener.document.getElementById(“女性”).checked)
document.getElementById(“女性”).checked=true;
}
姓名:
性别:男
女性

我认为如果用window.open打开弹出窗口,window.opener应该可以工作。 下面是一个非常粗糙的示例,它将从父级复制复选框html。 家长(try.html)

function loaded() {
    if(window.opener) {
    document.getElementById('tb').value =   window.opener.document.getElementById("cb").outerHTML
    }
}
</script>
    <body onload="loaded()">
        <form>
            <input type=text id=tb>
       </form>
   </body>
   </html>

函数openpopup(){
window.open('try2.html');
返回false;
}
子页面(try2.html)

function loaded() {
    if(window.opener) {
    document.getElementById('tb').value =   window.opener.document.getElementById("cb").outerHTML
    }
}
</script>
    <body onload="loaded()">
        <form>
            <input type=text id=tb>
       </form>
   </body>
   </html>
函数加载(){
if(窗口开启器){
document.getElementById('tb').value=window.opener.document.getElementById('cb').outerHTML
}
}

使用稍微修改过的代码(查看href链接),这段代码对我很有用

function loaded() {
    if(window.opener) {
    document.getElementById('tb').value =   window.opener.document.getElementById("cb").outerHTML
    }
}
</script>
    <body onload="loaded()">
        <form>
            <input type=text id=tb>
       </form>
   </body>
   </html>
    <html>
    <script>
    function openpopup() {
        window.open('try2.html');
        return false;
    }

    </script>
        <body>
            <form>

              Name: <input type="text" id="name"/>
        Gender: Male<input type="checkbox" name="gender" id="male"/>
            Female<input type="checkbox" name="gender" id="female"/><br />
     <a href="" onclick="javascript:return openpopup()">View</a>
   </form>

函数openpopup(){
window.open('try2.html');
返回false;
}
姓名:
性别:男
女性

function loaded() {
    if(window.opener) {
    document.getElementById('tb').value =   window.opener.document.getElementById("cb").outerHTML
    }
}
</script>
    <body onload="loaded()">
        <form>
            <input type=text id=tb>
       </form>
   </body>
   </html>
和my try2.html(您的popup.jsp)

function loaded() {
    if(window.opener) {
    document.getElementById('tb').value =   window.opener.document.getElementById("cb").outerHTML
    }
}
</script>
    <body onload="loaded()">
        <form>
            <input type=text id=tb>
       </form>
   </body>
   </html>

函数setThis(){
document.getElementById(“名称”).value=window.opener.document.getElementById(“名称”).value;
if(window.opener.document.getElementById(“男性”).checked)
document.getElementById(“男性”).checked=true;
if(window.opener.document.getElementById(“女性”).checked)
document.getElementById(“女性”).checked=true;
}
姓名:
性别:男
女性

话虽如此,我已经不再使用弹出窗口,而是使用页面弹出对话框。大多数时候,我使用JQuery UI Dialog

Bindrid时,这个技巧很好,但它仍然不能解决显示复选框值的问题。我尝试了你的代码。它仍然不显示复选框值。我会错过什么吗?好的。非常感谢你的帮助。我在setThis()后面加了一个分号。当我移除它时,它开始工作。我一直认为是否有分号并不重要。奇怪的
function loaded() {
    if(window.opener) {
    document.getElementById('tb').value =   window.opener.document.getElementById("cb").outerHTML
    }
}
</script>
    <body onload="loaded()">
        <form>
            <input type=text id=tb>
       </form>
   </body>
   </html>