[英]How to introduce JavaScript alert window inside PHP code
I need to introduce JavaScript alert function show_alert()
inside PHP code. 我需要在PHP代码中引入JavaScript警报功能
show_alert()
。 How this can be done? 如何做到这一点?
script type="text/javascript">
function show_alert() {
var msg = "No solution found.";
alert(msg);
}
</script>
<?php
//...
$outputs = -1;
if ($outputs == -1) {
echo '<script type="text/javascript"> show_alert(); </script>';
} else {
?>
<table width="100%">
<tr>
<td width="100%">
<div class="scrollbar" id="chart">
<img src="ganttchart.php">
</div>
</td>
</tr>
</table>
<?php
}
?>
In-line JavaScript needs to be inside <script>
tags. 内联JavaScript必须位于
<script>
标记内。 Simply output those as well, in a valid place. 只需将它们也输出到有效位置即可。 Do note that you cannot affect the operation of the PHP code this way though.
请注意,尽管如此,您不能影响PHP代码的操作。
Try this, it echos the show_alert(); 试试这个,它回显了show_alert(); in PHP:
在PHP中:
<script type="text/javascript">
function show_alert() {
var msg = "No solution found";
alert(msg);
}
</script>
<?php
//...
$output = run_function();
if ($output == -1) {
echo '<script type="text/javascript"> show_alert(); </script>';
}
?>
use this 用这个
<script type="text/javascript">
show_alert();
</script>
so like this 像这样
$output = run_function();
if ($outputs == -1) {
?>
<script type="text/javascript">
show_alert();
</script>
<?php
}
?>
I would suggest 我会建议
$msg = "My message";
echo "<script type=\"text/javascript\"> alert($msg); </script>";
You are right about it David 你是对的戴维
<?php
$output = run_function();
if ($outputs == -1) {
echo "<script type='text/javascript'>alert("No Solution Found");</script>"
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.