[英]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.