<分区>
我有一个 php 文件,其中包含一个切换可见性的按钮
echo "<button onclick = \"toggle('showDetails')\">expand</button>" ;
echo "<script type=\"text/javascript\">";
echo " function toggle(id) { \n";
echo " var e = document.getElementById(id)\n";
echo " if(e.style.display == 'block')\n";
echo " e.style.display = 'none';\n";
echo " else\n";
echo " e.style.display = 'block';\n";
echo " }";
echo " </script>";
它在我的 php 页面上运行得非常好。但是当我转到调用我的 php 页面的 html 页面时,脚本不起作用。我尝试将我的脚本放在 html 页面的标题和 html 页面的主体中,但无济于事。我需要做什么才能让我的按钮在 html 页面上工作。
编辑: 这是 showDetails 元素:
echo "<div id =\"showDetails\" style=\"display:none\">" ;
echo "<strong>client_address:</strong>" ;
echo $client_address;
echo "<br>" ;
echo "<strong>client_date:</strong>" ;
echo $client_date;
echo "</div>" ;
我还打开了我的 html 页面并使用了 google chrome 检查器。当我点击 html 页面上的按钮时,我在控制台中收到错误:
未捕获的 ReferenceError:未定义切换