繁体   English   中英

HTML display = none不起作用

[英]HTML display=none doesn't work

我的代码:

<?php
  if($counter==0) {
    echo "value of counter = $counter"
  ?>
  <script type='text/javascript'>
    document.getElementById("tt").style.display = "none";
  </script>
  <?php
  }
?>
<html>
<body>
  <form action="new_upload.php" method="post" name="myform" enctype="multipart/form-data" id="formform">
    <input type='submit' value='Go Back!' name="sbmt" id="tt"
      <?php if($counter==0) { ?> display="none" <?php } ?> />
  </form>
  <p> Submit a different file by clicking the back button in case your file was unable to upload.</p>
</body>
</html>

您可以看到我尝试通过以下方式将属性display = none设置为Submit按钮
1)如果php条件为true,则添加了javascript。
2)我在表单提交按钮代码中添加了php。
但它不能双向工作。 我可以通过print语句看到counter的值为0,但是它也是可见的。

您正在创建元素之前执行脚本。 将代码移到元素下方即可工作

没有display这样的属性,您需要改用style="display: none"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM