【问题标题】:How to show a html hidden div after clicking a submit button in another php file单击另一个php文件中的提交按钮后如何显示html隐藏的div
【发布时间】:2022-01-11 13:30:03
【问题描述】:

我在seosystem/index.php 中有这个 div

<div class="class" id="ScoreResult" style="display:none;">

  <div class="row border border-5 " style="background:whitesmoke;">

    <div class=" col toast w-20  z-depth-5 shadow-lg p-3 mb-5 bg-white rounded show w-100">
      <div class="toast-header">
        <strong class="me-auto">Description</strong>
        <!-- <button type="button" class="btn-close" data-bs-dismiss="toast"></button> !-->
      </div>
      <div class="toast-body ">
        <div class="progress" style="height:20px; width:200px;">
          <div class="progress-bar bg-success" style="width:33.33%"></div>
          <div class="progress-bar bg-warning" style="width:33.33%"> </div>
          <div class="progress-bar bg-danger" style="width:33.33%"> </div>
        </div>
        <p>10/10</p>
      </div>
    </div>

    <div class="col-sm   border border-5 col-xxl mx-auto">
      <h4><?php echo "Title: " . $title; ?></h4>
      <?php echo "<iframe style=\"background-color:whitesmoke;\" position=\"center\"allow=\"accelerometer\"; gyroscope;  width=\"100%\" height=\"315\" src=\"http://www.youtube.com/embed/$ytcode\" frameborder=\"0\" allowfullscreen></iframe></div>";
      ?>
    </div>
  </div>

我在seosystem/controller/youtubedata.php 有这个功能,我试过用 Js 没用 所以我希望当用户提交按钮时,它会显示 div 来显示数据

 if($_SERVER['REQUEST_METHOD'] == "GET" && isset($_GET['url']) && isset($_GET['submit'])){

    /*  echo  "</br >" ; 
    echo   $input_Url_data   .  "Button clicked" ;  */    
    $id_position = strstr($input_Url_data,"=");
    $id_position = trim($id_position, "=" );
    echo '<script type="text/javascript">',
 'showtable(){
    document.getElementById(<?php echo "ScoreResult" ;?>).style.display = "block";

 }',
 '</script>' ; 

}

这是输入和按钮的形式,我不确定我应该执行操作index.php 还是seosystem/controller/youtubedata.php

 <form class="d-flex justify-content-center " method="GET" action="index.php">
      <div class="input-group ">
        <input type="text" class="form-control" name="url" placeholder="Enter Youtube Video URL" aria-label="Example text with button addon" aria-describedby="button-addon1">
        <input class="btn" value="Analyze" name="submit" type="submit" id="button-addon1"></input>
      </div>
    </form>

【问题讨论】:

  • 在 JS 中你定义了一个函数,但你不运行它。
  • 我以为它会被自动调用我编辑它仍然无法工作if($_SERVER['REQUEST_METHOD'] == "GET" &amp;&amp; isset($_GET['url']) &amp;&amp; isset($_GET['submit'])){ /* echo "&lt;/br &gt;" ; echo $input_Url_data . "Button clicked" ; */ $id_position = strstr($input_Url_data,"="); $id_position = trim($id_position, "=" ); echo '&lt;script&gt; showtable(); &lt;/script&gt;'; }
  • 并在seosystem/controller/youtubedata.php&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; function showtable() { document.getElementById( "ScoreResult").style.display = "block"; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;script src="..\bootstrap\scriptname.js"&gt;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt;的第一部分添加了这部分
  • 我执行了 js 示例,它可以工作,你认为该函数无法读取 div 的 id,因为它来自另一个文件吗?

标签: javascript php html css


【解决方案1】:

那里有两个无效变量.. TITLE & YTCODE。嗯,我不知道你是怎么得到这些的。

但仅在响应有效时才显示 DIV,这是代码;

youtube.php
<?php

if($_SERVER['REQUEST_METHOD'] == "GET" && isset($_GET['url']) && isset($_GET['submit'])){

/*  echo  "</br >" ; 
echo   $input_Url_data   .  "Button clicked" ;  */    
$id_position = strstr($input_Url_data,"=");
$id_position = trim($id_position, "=" );
$verified_success = "yes"; // This is the conditional variable.
/* echo '<script type="text/javascript">',
'showtable(){
document.getElementById(<?php echo "ScoreResult" ;?>).style.display = "block";

}',
'</script>' ;  */

}
index.php
<?php

// Stop Irrelevant Warning Signs From Showing such as invalid variables
error_reporting(E_ERROR | E_PARSE);
include("youtube.php");
?>

<?php
                  if ($verified_success == NULL) {
                    ?>
<form class="d-flex justify-content-center " method="GET" action="">
      <div class="input-group ">
        <input type="text" class="form-control" name="url" placeholder="Enter Youtube Video URL" aria-label="Example text with button addon" aria-describedby="button-addon1">
        <input class="btn" value="Analyze" name="submit" type="submit" id="button-addon1"></input>
      </div>
</form>
<?php } ?>


<?php
    if ($verified_success != NULL) {
?>

<div class="class" id="ScoreResult">

  <div class="row border border-5 " style="background:whitesmoke;">

    <div class=" col toast w-20  z-depth-5 shadow-lg p-3 mb-5 bg-white rounded show w-100">
      <div class="toast-header">
        <strong class="me-auto">Description</strong>
        <!-- <button type="button" class="btn-close" data-bs-dismiss="toast"></button> !-->
      </div>
      <div class="toast-body ">
        <div class="progress" style="height:20px; width:200px;">
          <div class="progress-bar bg-success" style="width:33.33%"></div>
          <div class="progress-bar bg-warning" style="width:33.33%"> </div>
          <div class="progress-bar bg-danger" style="width:33.33%"> </div>
        </div>
        <p>10/10</p>
      </div>
    </div>

    <div class="col-sm   border border-5 col-xxl mx-auto">
      <h4><?php echo "Title: " . $title; ?></h4>
      <?php echo "<iframe style=\"background-color:whitesmoke;\" position=\"center\"allow=\"accelerometer\"; gyroscope;  width=\"100%\" height=\"315\" src=\"http://www.youtube.com/embed/$ytcode\" frameborder=\"0\" allowfullscreen></iframe></div>";
      ?>
    </div>
  </div>

  <?php } ?>

【讨论】:

  • 感谢解决,YTCODE 变量用于保存 youtube 视频 ID 并将其用于 &lt;iframe&gt;
  • 好的,不客气
猜你喜欢
  • 1970-01-01
  • 2022-01-11
  • 2021-06-14
  • 2016-03-02
  • 1970-01-01
  • 1970-01-01
  • 2016-05-21
  • 1970-01-01
  • 2017-07-22
相关资源
最近更新 更多