2012-11-13 42 views
0

说实话,我根本不懂JavaScript。我一直在通过观察别人来弄清楚事情,但这次不是这样!我希望我的一个表单能够以提交为中心弹出。我已经得到它弹出并保留表格数据到目前为止,但我似乎不能让它居中!这里是一些与我一起工作的代码:Popup form centered

此外,如果有人可以向我解释这将是伟大的。我的表单动作看起来有点像document.getElementByID('Name').vaule加上电子邮件等疯狂,但表单字段ID与动作不匹配,但它仍然工作。我不知道这一个或为什么它的实际工作仍http://www.computerbytez.com/develop.html在行动的形式

方式:!

<form action="https://computerbytez.com/InstantChat/Standard/logmein.html?Name=' + document.getElementById('Name').value + '&amp;Email=' + document.getElementById('Name').value, '', 'toolbar=no, status=no, menubar=no, titlebar=no, location=no, scrollbars=no, resizable=no, height=500, width=400'" id="lmiform"> 
      <div class="form-field"> 
     <label class="cm-required " for="elm_7">Name</label> <input class="input-text" id="elm_7" name="name" size="50" style="width: 100%; max-width: 372px;" type="text"/></div> 
<div class="buttons-container"> 
     <span class="button-submit button-wrap-left"><span class="button-submit button-wrap-right"><input type="submit" value="Connect To Technician" /></span></span></div> 

形式的JavaScript:

$(document).ready(function() { 
    $('#lmiform').submit(function() { 
window.open('', 'formpopup', 'width=620,height=480,scrollbars=no,resizable=no,top=200,left=200'); 
     this.target = 'formpopup'; 
    }); 
}); 

我也一直在搞乱这个(弹出中心的链接)和我一直在试图将两者结合在一起,没有运气:

<script> 
function PopupCenter(pageURL, title,w,h) { 
var left = (screen.width/2)-(w/2); 
var top = (screen.height/2)-(h/2); 
var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left); 
} 
</script> 

<a href="javascript:void(0);" onclick="PopupCenter('example.html', 'myPop1',620,470);"><img alt="" class="LMIpic" src="live_help_online.gif" /> </a> 

任何帮助将不胜感激。谢谢

+0

'javascript'无关用'java'。请勿误用标签。 – gdoron

回答

4

我已访问过您的网站,并且点击图片时弹出窗口显示居中且罚款。代码看起来很不错。尝试清除浏览器缓存。

编辑:

$(document).ready(function() { 
     $('#lmiform').submit(function() { 
      var left = (screen.width/2)-(620/2); 
      var top = (screen.height/2)-(480/2); 
      window.open('', 'formpopup', 'width=620,height=480,scrollbars=no,resizable=no,top='+top+',left='+left); 
      this.target = 'formpopup'; 
     }); 
    }); 
+0

已经有!它不是一个图像,它的按钮说“连接技术人员”,它现在从顶部和左侧打开200px。 – user1819416

+0

你的问题不是很清楚。如果您希望提交弹出窗口居中,请尝试上述回答中的编辑。 – 5hahiL

+0

顺便说一句,我正在谈论的PopupCenter()函数设置的live_help_online.gif图像。弹出窗口以您的功能正确居中。 – 5hahiL