javascript - PHP 中的图像和可见性

标签 javascript php css

我试图在 Stack Overflow 中找到这个问题,但由于没有找到它,所以我问它:

我正在尝试创建一个包含两列表格的程序。在第一列中我有一个图像,第二列是空的。当我点击图像时,我想在第二列中看到一个 URL。

如果我转到第二行并单击图像,那么第一行中的 url 将消失,第二行 url 将出现。这是我的代码,但由于某种原因我不知道它不起作用。如果有人可以提供任何意见或任何建议的代码,我将不胜感激:

<table class="table tb-mytable">
<?php if($as_result){?>
    <td class="img-parent"><img src="../../uploads/<?=$as_result['as_asset']?>" style="width:<?=$width/2?>px; height:<?=$height/2?>px;" class="<?=$as_result['as_id']?> test"  /></td>
    <td class="<?=$as_result['as_id']?> iframe-link">
        <?php echo htmlentities('<iframe frameborder="0" width="'.$width.'px" height="'.$height.'px" style="overflow:hidden;padding:0px; margin:0px;" scrolling="no" src="'.$site_url.'stream/?q=c_'.(filter_input(INPUT_GET, 'mycamp')).'|p_'.$_SESSION['code'].'|a_'.$as_result['as_id'].'"></iframe>                            ');?>
    </td>

这是 JavaScript 部分:

$('.img-parent').click(function(){
    $(this).next('td').css('visibility', 'visible');
});

这是CSS:

.iframe-link{
    visibility: hidden;
}

最佳答案

它可能对您不起作用,因为在您的 click 功能中,您只需更改包含 URL 的相邻第二列的 visibility。但是,您首先需要隐藏最后可见的 URL。一种解决方法是:

 $(function() {
 //Hide the second column as soon as the document loads
 //Although you shouldn't require this since your css already does it
 $( "td.iframe-link" ).css('visibility', 'hidden');

  //The click functions that toggles the visibility of the adjacent element
  $('.img-parent').click(function(){
     //Assuming the class for the adjoining td i.e the second column is iframe-link
     //Hide all such elements first
     $( "td.iframe-link" ).css('visibility', 'hidden');

     //Display the relevant element
     $(this).next('td').css('visibility', 'visible');
  });

});

希望这能让您朝着正确的方向开始。

关于javascript - PHP 中的图像和可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26248688/

相关文章:

javascript - href 链接未打开,单击时 Bootstrap 将开放类添加到下拉菜单而不是打开链接

javascript - 如何构建一个简单的网络切换?

javascript - 在 Angular 7 中使用 PathLocationStrategy 后刷新页面时获取 404

php - 适用于 iOS 的 Google 云消息传递 MismatchSenderId

php - 语法错误 : Unexpected EOF

css - 转换:旋转在 Safari 中不起作用

jquery - Angularjs - 当使用 ng-repeat 动态增加一个子 div 的大小时,如何使子 div 具有相同的高度

javascript - 使用 Sublime 连接文件?

php - 使用 jquery 和 php 检索 mysql 数据

javascript - 位置样式为绝对时滚动时的文本框定位问题