gpt4 book ai didi

javascript - 在 Sweet alert 2 中传递 PHP 变量

转载 作者:行者123 更新时间:2023-11-30 15:03:46 25 4
gpt4 key购买 nike

我想在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com