简短的答案是 你不能 。
我不知道任何PHP语法,但是我可以告诉您的是,PHP在服务器上执行,而Javascript在客户端(在浏览器上)执行。
您正在执行$ _GET,它用于检索表单值:
内置的$ _GET函数用于使用method =“ get”形式收集值。
换句话说,如果您的页面上有:
<form method="get" action="blah.php"> <input name="test"></input></form>
您的$ _GET调用将检索该输入字段中的值。
那么如何从Javascript检索值呢?
好吧,您可以将javascript值保留在隐藏的表单字段中…
<script type="text/javascript" charset="utf-8"> var test = "tester"; // find the 'test' input element and set its value to the above variable document.getElementByID("test").value = test;</script>... elsewhere on your page ...<form method="get" action="blah.php"> <input id="test" name="test" visibility="hidden"></input> <input type="submit" value="Click me!"></input></form>然后,当用户单击您的提交按钮时,他/她将向blah.php发出“ GET”请求,并发送“ test”中的值。



