Javascript onclick window.open不传递php变量

Javascript onclick window.open不传递php变量,javascript,php,html,Javascript,Php,Html,在使用以下命令时,我单击submit按钮,它会打开“domain.com/bhl.php?search=”并不会像我所需要的那样传递$GET变量 <form action="bhl.php" method="GET"> <input name="search" type="text" placeholder="Type here"> <input type="submit" onclick="window.open('bhl.php?search=&

在使用以下命令时,我单击submit按钮,它会打开“domain.com/bhl.php?search=”并不会像我所需要的那样传递$GET变量

<form action="bhl.php" method="GET">
    <input name="search" type="text" placeholder="Type here">
    <input type="submit" onclick="window.open('bhl.php?search=<?php echo $_GET['search'] ?>','targetWindow','toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=700, height=500'); return false;" />
</form>


它不起作用,因为当页面最初加载时,您正在读取搜索参数的值。PHP不会在页面加载后运行。单击按钮时,需要使用JavaScript设置值

<input type="submit" onclick="window.open('bhl.php?search=' + encodeURIComponent(this.form.search.value),'targetWindow','toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=700, height=500'); return false;" />

无法传递PHP变量,因为加载页面时没有值

尝试使用javascript发送值:

<form action="bhl.php" method="GET">
    <input id="search" type="text" placeholder="Type here">
    <input type="submit" onclick="window.open('bhl.php?search='+document.getElementById('search').value,'targetWindow','toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=700, height=500'); return false;" />
</form>


虽然我会定义一个函数,然后直接调用该函数,而不是使用内联javascript。

remove
onclick()
,但您可以在
bh1.php
中使用
$\u GET
。请注意,您使用引号的方式很奇怪。仅仅打开一堆不会按预期的方式工作(因为它看起来像是要关闭)。@FirstOne代码中的引号没有问题。@epascarello我可能弄错了,但我想我看到了
onclick='window.open('b..
。是否可能在没有显示编辑的情况下进行快速编辑?无论如何,很抱歉,我的错。。。