如何使用javascript向对话框显示PHP变量值?

how can i show php variable value to a dialogue box using javascript

本文关键字:PHP 变量值 显示 对话框 何使用 javascript      更新时间:2023-09-26

先生,我有一个问题与我的项目我计算了某些事情的总和在PHP变量说$sum,现在我想在一个对话框中显示它的值,如总和的特定的东西=计算总和使用java脚本我将如何做到这一点?这是我写的,它不起作用,我该怎么办?其中sum1是我想在JavaScript对话框中打印的变量值,size13到size24是我使用一些sql查询计算的。

index . php

<?php>   
     $sum1=$size13+$size14+$size15+$size16+$size17+$size18+$size19+$size20+$size21+$size22+$size23+$size24;
     echo '<script type="text/javascript">
     alert("Total Traffic-violation Solved During the year -2014-");
     echo $sum1;
     window.location=''index.php'';</script>';
<?>

将提示改为:

alert("Total Traffic-violation Solved During the year -2014-'.$sum1.'");

将总和连接到字符串中。

还要以结尾,而不是和& lt; ?比;-或者你正在使用一个非常非常奇怪的PHP解析器?

试试这个,在js alert()函数中使用$sum1变量;

  <?php>   
  $sum1=$size13+$size14+$size15+$size16+$size17+$size18+$size19+$size20+$size21+$size22+$size23+$size24;

  echo '<script type="text/javascript">
          alert("Total Traffic-violation Solved During the year -2014- '.$sum1.'");
          window.location=''index.php'';
        </script>';
    ?>

<script type="text/javascript">
   alert("Total Traffic-violation Solved During the year -2014- <?php echo $sum1; ?>");
   window.location=''index.php'';
</script>

可以:

<?php 
     $sum1 = 50;
     echo '<script type="text/javascript">
     alert("Total Traffic-violation Solved During the year -2014-: '.$sum1.'");
     window.location=''index.php'';
     </script>';
?>

你应该使用下一行

alert("Total Traffic-violation Solved During the year -2014-'.$sum1.'");