本文介绍了中心window.open在表单提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码如下所示:
<script type="text/javascript"> function directions(sacred) { var x = screen.width / 2 - 700 / 2; var y = screen.height / 2 - 450 / 2; window.open(sacred.action, 'Directions', 'height=485,width=700,left=' + x + ',top=' + y); return false; } </script> <form action="maps.google/maps" method="get" target="Directions" onsubmit="return directions(sacred);">我不懂js,所以如果看起来很草率,请放轻松。
I don't understand js, so take it easy on me if it looks sloppy.
我可以让它工作正常:
<form action="maps.google/maps" method="get" target="Directions" onsubmit="Directions=window.open('about:blank','Directions','width=600,height=400');">一旦我尝试将 onsubmit 连接到上面的剧本,我迷路了。我甚至都不知道上述功能是否可靠。
Once I try to connect the onsubmit to the above script, I get lost. I don't even know if the above function is reliable.
我在这里打开引擎盖: jsFiddle
I have popped open the hood here: jsFiddle
问题是表单提交到新选项卡,并忽略 window.open 一起。
The problem there is the form submits into a new tab, and ignores window.open altogether.
提前感谢您的帮助。
推荐答案试试这个: jsfiddle/333Qy/ 1 /
<script> function directions(sacred) { var x = screen.width / 2 - 700 / 2; var y = screen.height / 2 - 450 / 2; console.info(sacred); window.open(sacred.action, 'Directions', 'height=485,width=700,left=' + x + ',top=' + y); return false; } </script> <p> <form action="maps.google/maps" method="get" target="Directions" onsubmit="directions(this);"> <input class="directions-input" id="saddr" name="saddr" type="text" placeholder="enter zip-code" value="enter zip-code" onfocus="this.value = this.value=='enter zip-code'?'':this.value;" onblur="this.value = this.value==''?'enter zip-code':this.value;" /> <input type="submit" class="directions-submit" /> <input type="hidden" name="daddr" value="210+East+Northampton+Street,+Bath,+PA" /> <input type="hidden" name="hl" value="en" /> </form> </p>onsubmit应该是函数调用。此外,神圣是不确定的。我在上面的代码
onsubmit should be a function call. Also, sacred is undefined. I have made the changes in the above code
更多推荐
中心window.open在表单提交
发布评论