javascript - PHP 自动回显带有 onclick 的标签
问题描述
我想在js中做一个函数,它可以做一些事情。现在,当我加载页面时,它会运行此功能。但我不想那样。一切都得到了显示,就像我想要的那样。当我单击图像时,它会运行该功能。我将文件回显到另一个文件中。所以表格会显示在另一个 php 文件中。
echo "<table border='1'>
<tr>
<th>Item 1</th>
<th>Item 2</th>
</tr>
<tr>";
$counter = 0;
foreach($displayItemArray as $row)
{
echo '<td><a onclick="chosenItem('.$counter.')"><img src="data:image/jpeg;base64,'.base64_encode($row['ITEM']).'" width="500" height="auto"/></a></td>';
$counter += 1;
}
echo "</tr>
</table>";
?>
<script type="text/javascript">
function chosenItem(chosenItemNumber) {
if (chosenItemNumber == 0) {
"<?php $itemsLeft[] = $shuffledItems[1]; ?>";
"<?php unset($shuffledItems[1]); ?>";
} else {
"<?php $itemsLeft[] = $shuffledItems[0]; ?>";
"<?php unset($shuffledItems[0]); ?>";
}
"<?php $_SESSION[ $idshuffleditems ] = $shuffledItems; ?>";
"<?php $_SESSION[ $idleftitems ] = $itemsLeft; ?>";
getItems();
}
</script>
解决方案
推荐阅读
- angular - 构建命令失败 - Netlify
- python - (现值)我怎样才能一个一个地多个2范围?
- reactjs - 调用 setState 更新程序时 this.state 是否为当前状态?
- javascript - 获取无效 POST、PATCH 的 CORS 错误 - REST 端点
- javascript - 在使用 face-api.js 进行人脸检测后,有什么方法可以自动裁剪人脸?
- c# - 使用 C# 和 CMD 定义防火墙
- javascript - jspdf.html 方法不分页(或将内容推送到下一页)
- web-services - 当我尝试使用 Coldfusion Web 服务上传文件时出现 Enctype 问题
- c# - 尝试在 pod/容器中添加证书时出现权限被拒绝错误
- python - 根据字典顺序为字符串 s 分配唯一值