- 相關推薦
php動態(tài)生成JavaScript代碼
如何生成javascript的實現代碼,就跟隨百分網小編一起去了解下吧,想了解更多相關信息請持續(xù)關注我們應屆畢業(yè)生考試網!
復制代碼 代碼如下:
<?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動態(tài)生成JavaScript代碼】相關文章:
php生成縮略圖的兩種方法(代碼)12-07
php語言字典代碼03-18
php下載代碼怎么寫11-18
PHP源代碼方式詳解11-17
JavaScript代碼的5個書寫壞習慣03-30
20條PHP代碼優(yōu)化技巧05-06
PHP生成Word文檔的方法11-21