如何返回在php中保存确认的javascript函数

How to echo javascript function that holds confirmation inside php

本文关键字:保存 确认 函数 javascript php 何返回 返回      更新时间:2023-09-26

需要一些帮助,在PHP中调用javascript函数,基本上在我的控制器编码器中。脚本是在视图页面上编写的。现在,我在控制器内部调用

视图页面:

     function confirmation() {
    var txt;
    var r = confirm("Press a button!");
    if (r == true) {
        txt = "You pressed OK!";
    } else {
        txt = "You pressed Cancel!";
    }
    document.getElementById("demo").innerHTML = txt;
}

控制器:

echo 'confirmation()';

如果正确理解了这一点,你会希望你的函数在视图操作的特定点执行。

在这种情况下,只需打印javascript代码正好在你想要它在视图操作中显示的位置。

<script type="text/javascript">
  confirmation();
</script>

如果你不能回送,那么使用require_once()或include_once()来包含文件,该文件可以是。php或简单的。js文件。