<script type="text/javascript">
function Invest()
{
alert("Mechanical /n Electrical /n Computer /n Civil");
}
function create()
{
alert("Graphic /n Interior /n Architecture");
}
function motivate()
{
alert("Business Administration /n Accounting and Finance");
}
</script>
以上代码是我的javascript代码
<form action="main.html" method="post">
<?php
$v2 = $_GET['dropdown'];
if ($v2=="investigative" )
{
echo "<h3>It's recommended that you follow</h3><h2>Engineering School</h2>";
}
else if ($v2=="creative" )
echo "<h3>It's recommended that you follow</h3><h2>Arts School</h2>";
else if ($v2=="motivated" )
echo "<h3>It's recommended that you follow</h3><h2>Business School</h2>";
?>
我想要做的是将我的回声更改为div onclick,这样它将从javascript中调用我的函数并显示其中的信息。
像这样的东西
echo ""<div onclick=Invest();"<h3>It's recommended that you follow</h3><h2>Engineering School</h2>";
当我这样做以为我收到错误
解析错误:语法错误,意外'onclick'(T_STRING),期待','或';'在第35行的C:\ xampp \ htdocs \ MyProject \ eval.php
我做错了什么以及如何做到这一点?我是php的新手:/
答案 0 :(得分:2)
不是这样的echo ""<div onclick=Invest();...
你需要像这样把div标签放在双引号内,用于onclick属性打开单引号,因为双引号已经打开
echo "<div onclick='Invest()'><h3>It's recommended that you follow</h3><h2>Engineering School</h2></div>";