php动态生成JavaScript代码
程序员文章站
2022-06-15 23:22:47
复制代码 代码如下:
<?php
echo <<<js //使用多行输出的方法输出javascript代码
<script language = "javascript">
function func()
{
if(confirm("are you ok with this?"))
{
document.write("i'm ok!");
}
else
{
document.write("i'm not ok!");
}
}
</script>
js;
?>
<html>
<head>
</head>
<body>
<a href="#" href="#" onclick="javascript:func();">please click</a>
</body>
</html>
<?php
$confirm = "are you ok with this?"; //定义确认框上的信息
$ok_msg = "i'm ok!"; //ok时的信息
$not_ok_msg = "i'm not ok!"; //cancel时的信息
echo "<script language = \"javascript\">"; //开始逐行输出javascript代码
echo "function func()";
echo "{";
echo "if(confirm(\"are you ok with this?\"))";
echo "{";
echo "document.write(\"i'm ok!\");";
echo "}";
echo "else";
echo "{";
echo "document.write(\"i'm not ok!\");";
echo "}";
echo "}";
echo "</script>"; //输出结束
?>
<html>
<head>
</head>
<body>
<a href="#" href="#" onclick="javascript:func();">please click</a>
</body>
</html>
复制代码 代码如下:
<?php
echo <<<js //使用多行输出的方法输出javascript代码
<script language = "javascript">
function func()
{
if(confirm("are you ok with this?"))
{
document.write("i'm ok!");
}
else
{
document.write("i'm not ok!");
}
}
</script>
js;
?>
<html>
<head>
</head>
<body>
<a href="#" href="#" onclick="javascript:func();">please click</a>
</body>
</html>
复制代码 代码如下:
<?php
$confirm = "are you ok with this?"; //定义确认框上的信息
$ok_msg = "i'm ok!"; //ok时的信息
$not_ok_msg = "i'm not ok!"; //cancel时的信息
echo "<script language = \"javascript\">"; //开始逐行输出javascript代码
echo "function func()";
echo "{";
echo "if(confirm(\"are you ok with this?\"))";
echo "{";
echo "document.write(\"i'm ok!\");";
echo "}";
echo "else";
echo "{";
echo "document.write(\"i'm not ok!\");";
echo "}";
echo "}";
echo "</script>"; //输出结束
?>
<html>
<head>
</head>
<body>
<a href="#" href="#" onclick="javascript:func();">please click</a>
</body>
</html>
上一篇: php模板原理讲解