我想在 sweet alert 中显示 PHP 变量但无法找到解决方案,我浏览了 sweet alert 2 的文档但找不到任何东西。 谁能帮帮我?
这是我的代码
$name = "xyz";
//sweetalert code
echo "<script>";
echo 'setTimeout(function () { swal("Greetings $name!","Thank you for adding your business details.<br>Our admin team will review the same and will publish shortly..!","success");';
echo '}, 100);</script>';
最佳答案
只需要切换引号:
echo "setTimeout(function () { swal('Greetings $name!','Thank you for adding your business details.<br>Our admin team will review the same and will publish shortly..!','success');'";
或者,另一种选择,在字符串中连接变量:
echo 'setTimeout(function () { swal("Greetings ' . $name . '!","Thank you for adding your business details.<br>Our admin team will review the same and will publish shortly..!","success");';
当你在 echo 中包含一个变量时,你需要使用 "
了解"
和'
之间的区别 SO Answer
关于javascript - 在 Sweet alert 2 中传递 PHP 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46113359/