如何使用window.open JavaScript函数发送变量

时间:2015-08-02 22:13:43

标签: javascript php

我想在使用<script type="text/javascript"> function getData(p1) { alert("Variable is: " + p1); <?php $club=window.title.value; $username="user"; $password="password"; $database="database"; $datahost="example.db.4729287.hostedresource.com"; mysql_connect($datahost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM golfinfo WHERE clubname = 'Mirabel'"; $result=mysql_query($query); $row = mysql_fetch_array($result); ?> alert("row is: " + p1); window.ClubName.value= "<?php echo $row['ClubName'] ?>"; window.Privacy.value = "<?php echo $row['Privacy'] ?>"; window.Membership.value = "<?php echo $row['Membership'] ?>"; window.Type.value = "<?php echo $row['Type'] ?>"; } </script> 函数时将变量发送到新窗口。这是我的代码:

window.open

我正试图将PHP变量<html> <head>`enter code here` <script> function myFunction(){ window.open('test4.php?id=5', '_blank', 'toolbar=0,location=0,menubar=0'); } </script> </head> <body> <?php $id=5; ?> <button onclick="myFunction()">Click Here</button> </body> </html> 传递给下一页。

1 个答案:

答案 0 :(得分:2)

<html>
<head>`enter code here`
 <script>
 function myFunction(value){
// getting value you want to pass
 window.open('test4.php?id=' + value, '_blank', 'toolbar=0,location=0,menubar=0');

}
 </script>
 </head>
 <body>
 <?php
 $id=6;
?>

//you can add php value in any html like that.
 <button onclick="myFunction(<?php echo $id;?>)">Click Here</button>
 </body>
 </html>

作为最后的说明: 在提出这样的问题之前,你应该参考这些主题的教程。