首页 > 解决方案 > 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>

标签: javascriptphp

解决方案


推荐阅读