繁体   English   中英

PHP echo JS包含PHP变量

[英]PHP echo JS which includes PHP variable

我有sendForm.php文件,这是使用PHPMailer发送表单的php。 在标签之间有回声,我需要在标签之间使用PHP变量。 这有可能吗? 我知道这太结合了PHP和JS,但是我能做什么......我需要一个窗口弹出窗口,这也是我使用JS的原因。 echo本身只打印到网页本身。

$totalSize = ($totalSize/(1024*1024));
$totalSize = round($totalSize,2);

if(!$mail->Send()) {
   echo "Error sending form! You are trying to send too large files. Their size is: ", $totalSize, " MB";
   echo '<script type="text/javascript">alert("Error sending form! You are trying to send too large files. Their size is: ??? ");</script>';
   }

如何在JS内部打印$ totalSize变量代替第二个回声中的那些问号呢? 谢谢你的帮助。 我还是个初学者。

if(!$mail->Send()) {
   echo "Error sending form! You are trying to send too large files. Their size is: ". $totalSize. " MB";
   echo '<script type="text/javascript">alert("Error sending form! You are trying to send too large files. Their size is: '. $totalSize. '");</script>';
   }

//我纠正了第一个echo中的一些错误(用点替换逗号)

PHP是服务器端语言 ,而JavaScript是客户端语言 如果您尝试在服务器端验证表单而不重新加载页面(并让JavaScript弹出警告),请查看AJAX

尝试这个

  if(!$mail->Send()) {
    echo "Error sending form! You are trying to send too large files. Their size is: ".$totalSize." MB";
        ?>
<script type="text/javascript">
alert("Error sending form! You are trying to send too large files. Their size is: <?php echo $totalSize;?> ");
</script>
<?php } 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM