Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.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 - Fatal编程技术网

使用表单JavaScript中的值创建弹出窗口

使用表单JavaScript中的值创建弹出窗口,javascript,html,Javascript,Html,我试图打开一个新窗口,其中包含从id为“name”的textfield接收到的值 打开 这是javascript: function openWindow() { newWindow = window.open("", null, "height=200,width=400,status=yes,toolbar=no,menubar=no,location=no"); newWindow.document.write("<h1>"+document.myForm.name.

我试图打开一个新窗口,其中包含从id为“name”的textfield接收到的值


打开
这是javascript:

function openWindow() {
newWindow = window.open("", null, "height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");  

newWindow.document.write("<h1>"+document.myForm.name.value+"</h1>");
}
函数openWindow(){ newWindow=window.open(“,null,“高度=200,宽度=400,状态=yes,工具栏=no,菜单栏=no,位置=no”); newWindow.document.write(“+document.myForm.name.value+”); } 它可以,但为什么它会清空表单值?

我怎样才能使这个新窗口居中?可能高度=window.height()/2

在我这方面效果很好,尝试了你的代码。在点击按钮之前,别忘了在输入框内写些东西。如果它不起作用

请尝试以下方法:

newWindow.document.write("<h1>"+document.getElementById('name').value+"</h1>");
newWindow.document.write(“+document.getElementById('name').value+”);

禁用onclick事件,它将提交表单。 将其添加到表单标记,然后在函数底部返回false。
是否创建弹出窗口?还是窗户?两件不同的事情。为什么不使用alert()@GeekByDesign window抱歉,我需要这个新窗口稍后进行交互,以更改值等…因为您没有将
myForm
声明为实际元素。或者干脆。@SpencerMay在openWIndow方法之外,比如var someText[]=document.myForm?pff不起作用,当新窗口弹出时仍会清空表单,因为窗口居中放置'var left=(screen.width/2)-(w/2);变量top=(屏幕高度/2)-(h/2);`在函数中,将“top=”+top+”,left=”+left)放在打开的窗口中
newWindow.document.write("<h1>"+document.getElementById('name').value+"</h1>");