//this is in php
function msgbox($msg, $type)
{
if ($type == "alert")
{
// Simple alert window
?> <script language="JavaScript"> alert("<? echo $msg; ?>"); </script> <?
}
elseif ($type == "confirm")
{
// Enter Confirm Code Here and assign the $result variable for use
// Should include "OK" and "Cancel" buttons.
?>
<script language="JavaScript">
if (confirm("<? echo $msg; ?>"))
{
<? $result == "ok"; ?>
}
else
{
<? $result == "cancel"; ?>
}
</script>
<?
}
}
if ($page_title->exists())
{msgbox("page exists,do you want to delete", "confirm");
}
if ($result == "ok")
//code..
问题是$result
没有从确认框中读取值,我认为是因为 if 子句没有被执行,并且程序流程将转到没有 if 子句的情况下。
您不能以这种方式混合服务器端代码 (PHP) 和客户端代码。
对于要更改 PHP 状态的 javascript,您需要进行 HTTP 调用(经常使用 AJAX)。
您需要阅读 PHP 教程并确保掌握其中的概念。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)