[英]How to echo javascript function that holds confirmation inside php
need some help on calling javascript function inside php basically inside my controller codeigniter. 在我的控制器codeigniter内部,基本上需要在php内调用javascript函数时需要一些帮助。 the script was writtten on the view page.
该脚本在视图页面上被写错了。 Now, i'm calling in inside my controller.
现在,我在控制器内部打电话。
View page: 查看页面:
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;
}
Controller: 控制器:
echo 'confirmation()';
If understand this correctly you want your function to execute at a specific point of your view action. 如果正确理解这一点,则希望函数在您的视图操作的特定点执行。
In that case just print the javascript code exactly where you want it to show up in your view action. 在这种情况下,只需将javascript代码准确打印在您希望其在view action中显示的位置即可。
<script type="text/javascript"> confirmation(); </script>
If you can't echo that, then use require_once() or include_once() to include the file which may be a .phtml or simple .js file. 如果无法回显,请使用require_once()或include_once()包含文件,该文件可能是.phtml或简单的.js文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.