黑帽联盟
标题:
php动态生成JavaScript代码
[打印本页]
作者:
heimao
时间:
2017-2-26 20:20
标题:
php动态生成JavaScript代码
php动态生成JavaScript代码,直接上传代码:
<?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>
复制代码
欢迎光临 黑帽联盟 (https://bbs.cnblackhat.com/)
Powered by Discuz! X2.5