我是php新手。我只想制作一个隐藏或取消隐藏div的按钮 我在php块中放置了一个代码 当我在php block.button中编写代码时不能正常工作; 当我在php块之外编码它然后它运行。 为什么它不能在php块中运行?
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
echo"<button onclick='myFunction('confession13')'>Comment</button>
<div id='confession13'>
<p>hlo world</p>
</div>";
?>
<script type="text/javascript">
function myFunction(p1)
{
console.log(p1);
var x = document.getElementById(p1);
if (x.style.display === "none")
{
x.style.display = "block";
}
else {
x.style.display = "none";
}
}
</script>
</body>
</html>
答案 0 :(得分:0)
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<button onclick='myFunction("confession13")'>Comment</button>
<div id='confession13'>
<p>hlo world</p>
</div>
<script type="text/javascript">
function myFunction(p1)
{
console.log(p1);
var x = document.getElementById(p1);
if (x.style.display === "none")
{
x.style.display = "block";
}
else {
x.style.display = "none";
}
}
</script>
</body>
</html>