Javascript 如何在php外部调用函数?
当我在消息框中填写电子邮件地址列表并单击submit按钮时,当我使用此代码发布消息时,如何从php中的javascript调用closepopup函数Javascript 如何在php外部调用函数?,javascript,php,Javascript,Php,当我在消息框中填写电子邮件地址列表并单击submit按钮时,当我使用此代码发布消息时,如何从php中的javascript调用closepopup函数 if (!empty($_POST['message'])) { $emails = explode("\n", $_POST['message']); // explode textarea on a line break into an array $email_str = implode(", ", $emails); /
if (!empty($_POST['message']))
{
$emails = explode("\n", $_POST['message']); // explode textarea on a line break into an array
$email_str = implode(", ", $emails); // take each of the emails and implode together with the ,
}
当我尝试这个的时候
if (!empty($_POST['message']))
{
$emails = explode("\n", $_POST['message']); // explode textarea on a line break into an array
$email_str = implode(", ", $emails); // take each of the emails and implode together with the ,
closePopUp();
}
它会给我一个错误:致命错误:在第6行的/home/myusername/public_html/PHP/examples/send.PHP中调用未定义的函数closePopUp
以下是完整的代码:
<?php
if (!empty($_POST['message']))
{
$emails = explode("\n", $_POST['message']); // explode textarea on a line break into an array
$email_str = implode(", ", $emails); // take each of the emails and implode together with the ,
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Send Email</title>
<link type="text/css" rel="stylesheet" href="style.css" />
</head>
<body>
<form action="pr_send.php" method="POST">
<table>
<!-- <tr>
<td>From:</td>
<td><input type="text" name="from"></td>
</tr> -->
<tr>
<td><input type="button" name="to" value="" style="height:24px; width:24px; background:url('addressbook.png'); border:none;" onClick="Popup()"> To:</td>
<td><input type="text" name="to" value="<?php if (!empty($email_str)) { echo $email_str; } ?>" style="height:15px; width:650px"></td>
</tr>
<tr>
<td>Subject:</td>
<td><input type="text" name="subject" style="height:15px; width:650px"></td>
</tr>
<tr>
<td>Message:</td>
<td><textarea name="message" cols="90" rows="20"></textarea></td>
</tr>
<tr>
<td colspan="2" align="left">
<input type="submit" name="send" value="" style="height:35px; width:100px; background:url('send.png'); border:none">
</td>
</tr>
</table>
</form>
</body>
<script type="text/javascript">
var popup = null;
function Popup()
{
window.open("add_address.php", "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=100, left=500, width=400, height=400");
}
function closePopUp()
{
if (popup)
{
popup.close();
}
}
</script>
</html>
我们可以像这样在php代码中调用javascript函数
if (!empty($_POST['message']))
{
$emails = explode("\n", $_POST['message']); // explode textarea on a line break into an array
$email_str = implode(", ", $emails); // take each of the emails and implode together with the ,
echo '<script> closePopUp(); </script>'; //call javascript function
}
它是未定义的,您直接在PHP脚本中调用javascript函数,它不是这样工作的,PHP是服务器端,javascript是客户端side@Ghost是的,我知道,但我想关上窗户。我怎么能做到呢?@TimCullen提交后,在add_地址内关闭窗口。php@Ghost哦,好的,那你怎么用它来关闭弹出窗口呢?谢谢你,但当我尝试它时,它不起作用。如何关闭窗口并在add_address.php中输出消息中的电子邮件地址,以将其输出到send.php的文本框中?