douna1892 2017-03-21 06:58
浏览 83
已采纳

如何在单击时将div的id传递给另一个php页面

I want to pass the id of a particular div in a P.H.P page to another P.H.P page when it is clicked dynamically.The div who's id i want to pass, is created dynamically.So far I have fetched the id of the div dynamically by using Java script, but i cant seem to pass this value to another P.H.P page.

<?php 
    while ($row = mysql_fetch_assoc($result))
{
      $link = $row["video_link"];
                            $video_id = explode("?v=", $link);
                            $video_id = $video_id[1];

?>
 <div class="col-md-4 col-sm-4 col-xs-12">
 <div class="post_list_content_unit">
    <div class="post_list_featured_image"  onclick="markActiveLink(this);" id="<?php echo  $video_id?>">

    <script type="text/javascript">
    function markActiveLink(e) {   
    alert(e.id);
}
</script>
<a href="video_tut.php" title="View post details">
    <img width="370" height="193" src="http://img.youtube.com/vi/<?php echo  $video_id?>/hqdefault.jpg" class="img-responsive wp-post-image" alt="Teen girl sitting with a laptop" />

?>
  • 写回答

1条回答 默认 最新

  • dongyong9224 2017-03-21 07:24
    关注

    Not sure if this will suffice, but you could try this:

    <a href="<?php echo 'video_tut.php?vid_id='.$video_id; ?>" title="View post details">
        <img width="370" height="193" src="http://img.youtube.com/vi/<?php echo  $video_id?>/hqdefault.jpg" class="img-responsive wp-post-image" alt="Teen girl sitting with a laptop" />
    </a>
    

    Instead of getting the id from the div, I added the id as a GET query in the href of the a element. Then in the video_tut.php, you can use this to get the id value:

    if(isset($_GET['vid_id'])){
        $vidID = $_GET['vid_id'];
    }
    

    Here I'm assuming that exposing the $video_id in the URL does not pose some sort of security risks.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用