使用javascript和php的Src开关

使用javascript和php的Src开关,javascript,php,html,Javascript,Php,Html,我想,当您单击列表中的一个视频或图像时,它将更改主图像/视频。我已经这样做了,但问题是,当我添加视频部分时,它将不再工作,这里是代码 <div id="Post-Image"> <img id="Post-Image-Pic" src="<?php echo $row["Post_1"];?>" width="408" alt="#"/

我想,当您单击列表中的一个视频或图像时,它将更改主图像/视频。我已经这样做了,但问题是,当我添加视频部分时,它将不再工作,这里是代码

  <div id="Post-Image">
    <img id="Post-Image-Pic" src="<?php echo $row["Post_1"];?>" width="408" alt="#"/>
  </div> 
  <video controls id="Post-Video">
    <source  id="Post-Video-Source" src="<?php echo $row["Post_1"];?>" >
  </video>

<div id="List"> // this is the list
  <?php 
    $Video_Allow  = array('avi', 'mov', 'qt', 'mkv', 'mp4', 'avchd', 'flv', 'swf');
    $Image_Allow = array('jpg', 'jpeg', 'png', 'pdf', 'gif');
    if ($row["Post_1"] != "") {
      ?>
        <style> #Post-List{ display: none; }</style>
        <?php
          $File_Ext_1 = explode('.', $row["Post_1"]);
          $File_Actual_Ext_1 = strtolower(end($File_Ext_1));
          if (in_array($File_Actual_Ext_1, $Image_Allow)) {
           ?>
              <img src="<?php echo $row["Post_1"];?>" onclick="MyImage1();
                document.getElementById('Post-Image-Pic').src='<?php echo $row["Post_1"];?>';
                document.getElementById('Post-Video').style.display= 'none';
                document.getElementById('Post-Image').style.display= 'block';
              "/>
            <?php
          }elseif (in_array($File_Actual_Ext_1, $Video_Allow)) {
            ?>
              <video src="<?php echo $row["Post_1"];?>" onclick="MyImage1(); 
                document.getElementById('Post-Video-Source').src='<?php echo $row["Post_1"];?>'; 
                document.getElementById('Post-Video').style.display = 'block';
                document.getElementById('Post-Image').style.display = 'none';
              "/>
            <?php
          }
        ?>
      <?php
    }
?>
</div>

看,这是当你点击一个图像/视频时,它会改变你每篇文章的评论,这意味着一个图像/视频有一个评论部分。

所以在
MyImage1
之前,它工作得很好,但是你在
onclick
中添加了一堆额外的代码,现在什么都不工作了?图像和视频都没有
id
。。。?Where/what是
MyImage1()
?我需要您修复'document.getElementById('Post-Image-Pic')。src=''`是的,对不起,我错过了顶部的元素/ID。如果看不到
MyImage1()
,很难说发生了什么。
都没有
值,因此在它们上设置
.val()
将不起作用。到底发生了什么?控制台上有错误吗?如果你想看到其他页面,我正在编辑它
        var stm1 = document.getElementById("Comment1"),
            stm2 = document.getElementById("Comment2"),
            stm3 = document.getElementById("Comment3"),
            stm4 = document.getElementById("Comment4"),
            stm5 = document.getElementById("Comment5"),
            stm6 = document.getElementById("Comment6");
        stm1.style.display = "block";
        stm2.style.display = "none";
        stm3.style.display = "none";
        stm4.style.display = "none";
        stm5.style.display = "none";
        stm6.style.display = "none";
        function MyImage1() {
            stm1.style.display = "block";
            stm2.style.display = "None";
            stm3.style.display = "None";
            stm4.style.display = "None";
            stm5.style.display = "None";
            stm6.style.display = "None";
        }
        function MyImage2() {
            stm1.style.display = "none";
            stm2.style.display = "block";
            stm3.style.display = "none";
            stm4.style.display = "none";
            stm5.style.display = "none";
            stm6.style.display = "none";
        }