如何仅在提交表单后显示Div标签?

时间:2019-04-06 14:01:54

标签: php html forms

仅在表单提交后如何显示div标签?

通过使用js或php ..!

我想在提交表单后显示<div id=submitButton>

Div标签代码:

<script type="javascript">
function onSubmit(){
    document.getElementById('submitButton').style.display = "none";
    document.getElementById('progressBar').style.display = "block";
}
</script>

<video id='video01'  width='160' height='90' data-autoresize='fit' data-volume=".5"  >
  <source type="video/mp4" src="<?php $data = json_decode($getGP, true); echo $data[1]['file'];?>" />
 <source type="video/mp4" src="<?php $data = json_decode($getGP, true); echo $data[0]['file'];?>" data-quality="hd"/>
</video>

<div id="submitButton">

<button class="button button1" ><a class='afterglow' id="mytrigger" href="#video01">Play Now</a></button>

</div>

HTML表单代码:

<form action="" method="POST" onSubmit="return onSubmit()"return false;>
    <input type="text" size="80" name="url" value="https://photos.google.com/share/AF1QipMTEPAiVF8t0YqLukflnOSQjwfd8ARIoT2h37AXvYO1uaWodbeiFoBUDuD_19tEbg/photo/AF1QipPA2Bq0JlAR9LoGD3mogsxSb9OZWEG4XqBDD4Rv?key=cjhUT0xrZjM5NGN2SVRLOVptZU5SMUlKV0lQYWpB"/>
    <input type="submit" value="Load Now" name="submit" />
</form>

2 个答案:

答案 0 :(得分:1)

<?php
    if( $_SERVER['REQUEST_METHOD']=='POST' ){
?>

<div id="submitButton">
    <button class="button button1" ><a class='afterglow' id="mytrigger" href="#video01">Play Now</a></button>
</div>

<?php
    }//close if
?>

答案 1 :(得分:0)

如果您想使用JavaScript实现,可以创建一个CSS类规则来最初隐藏<div id="submitButton">,然后在onSubmit()函数回调中添加一个CSS类来更改从display:none;display:block;的显示类似以下内容:

function onSubmit(){
  var element = document.getElementById('submitButton')
  element.className += "show-ele";
}
.hide-ele {
  display: none;
}

.show-ele {
  display:block;
} 
<!DOCTYPE html />
<html>
  <head>
  </head>
  <body>
    <div id="submitButton" class="hide-ele">Submit Button Div</div>

    <form action="/" method="POST" onSubmit="return onSubmit()"return false;>
      <input type="text" size="80" name="url" value="<Insert your Video URL here>"/>
      <input type="submit" value="Load Now" name="submit" />
    </form>
  </body>
</html>

然后,您可以通过添加相应的hide-eleshow-ele CSS类来管理元素的显示/隐藏。

希望有帮助!