我想在$re
变量中得到的值用于Javascript函数变量var $r
:
<?php
include('functions.php');
if(!isLogIn()){<br>
$_SESSION['msg']="You must log in first";
header('location:login.php');
}
$orderid=$_GET['id'];
$Maxid=mysqli_query($db,"sql query here");
$result=mysqli_fetch_assoc($MAxid);
$re=$result['printst'];
<script type="text/javascript">
function print(){
var $r=<?php $re;?>;
if($r==1){
window.print();}
else{
return false}
答案 0 :(得分:0)
你可以使用echo函数将php结果注入javascript,如下所示:
include('functions.php');
if(!isLogIn()){
$_SESSION['msg']="You must log in first";
header('location:login.php');
}
$orderid=$_GET['id'];
$Maxid=mysqli_query($db,"sql query here");
$result=mysqli_fetch_assoc($MAxid);
$re=$result['printst'];
//assuming this is the javascript part
function print(){
var $r=<?php echo $re;?>;
if($r==1){
window.print();}
else{
return false}
答案 1 :(得分:0)
您需要将该变量传递给您的JS文件,如此
<script>
var $r= '<?php echo $re; ?>';
</script>
//你的js文件使用那个变量
function print(){
if($r==1){
window.print();}
else{
return false}