黑帽联盟

标题: php动态生成JavaScript代码 [打印本页]

作者: heimao    时间: 2017-2-26 20:20
标题: php动态生成JavaScript代码
php动态生成JavaScript代码,直接上传代码:
  1. <?php
  2. echo <<<JS //使用多行输出的方法输出JavaScript代码
  3. <SCRIPT Language = "JavaScript">
  4. function func()
  5. {
  6. if(confirm("Are you OK with this?"))
  7. {
  8. document.write("I'm OK!");
  9. }
  10. else
  11. {
  12. document.write("I'm not OK!");
  13. }
  14. }
  15. </SCRIPT>
  16. JS;
  17. ?>
  18. <html>
  19. <head>
  20. </head>
  21. <body>
  22. <a href="#" href="#" onClick="javascript:func();">Please Click</a>
  23. </body>
  24. </html>
复制代码
  1. <?php
  2. $confirm = "Are you OK with this?"; //定义确认框上的信息
  3. $ok_msg = "I'm OK!"; //OK时的信息
  4. $not_ok_msg = "I'm not OK!"; //Cancel时的信息

  5. echo "<SCRIPT Language = \"JavaScript\">"; //开始逐行输出JavaScript代码
  6. echo "function func()";
  7. echo "{";
  8. echo "if(confirm(\"Are you OK with this?\"))";
  9. echo "{";
  10. echo "document.write(\"I'm OK!\");";
  11. echo "}";
  12. echo "else";
  13. echo "{";
  14. echo "document.write(\"I'm not OK!\");";
  15. echo "}";
  16. echo "}";
  17. echo "</SCRIPT>"; //输出结束
  18. ?>
  19. <html>
  20. <head>
  21. </head>
  22. <body>
  23. <a href="#" href="#" onClick="javascript:func();">Please Click</a>
  24. </body>
  25. </html>
复制代码





欢迎光临 黑帽联盟 (https://bbs.cnblackhat.com/) Powered by Discuz! X2.5