我想传递四个参数事件,$ row ['title'],$ row ['username']和$ row ['date']。
<?php
echo "<script>
function increasevotes(e,location,user,date)
{
e.preventDefault();
console.log(\"Hi!\");
}
</script>";
//I've proper code here for fetching the mySQL query results into $rows and that part is working perfectly.
while($rows=mysqli_fetch_array($result))
{
if($rows['public']=="yes")
{echo "<span class=\"right\" id=\"nolikes\">{$rows['vote']}</span><a href=\"\" onclick=\"increasevotes(event,\"{$rows['title']}\",\"{$rows['username']}\",\"{$rows['date']}\")\"><img src=\"img/like.png\" class=\"right\" width=\"30\" height=\"30\"/></a>";
}
?>
实际上正在做的是,页面正在刷新。 当我单击查看源页面时,会显示:
<span class="right" id="nolikes">0</span>
<a href="" onclick="increasevotes(event,"chennai","venkat","01/07/2017")"><img src="img/like.png" class="right" width="30" height="30"/>
</a>
答案 0 :(得分:1)
将功能参数的双引号更改为单引号
onclick="increasevotes(event,'chennai','venkat','01/07/2017')"
或使用\
来转义引号。