如果在“ href”方向上没有文件,如何隐藏整个跨度

问题描述 投票:0回答:2

我在隐藏空白链接方面有问题。请有人帮我。:

<a href="/sunsetplanlama/<?php echo $sonuc['proje_ismi'] ?>/kumas_1.png"  data-lightbox="kumas" data-title="<?php echo $sonuc['proje_ismi'] ?>" class="tab active"  >
K1
</a>

如果"href="/sunsetplanlama/<?php echo $sonuc['proje_ismi'] ?>/kumas_1.png"不会比我想要的"K1"隐藏字母..

我该怎么做?

javascript php html hide
2个回答
0
投票

需要考虑的几点:

  • 服务器端解决方案是不合适的:您要测试客户端的资源可用性,并且只有在客户端作为代理时才能实现。
  • 检查资源可能需要一些时间,特别是比在客户端呈现html所需的时间更多。视可见的标记(例如示例中的span元素)而定,如果检索资源失败,则可能导致渲染的材料短暂显示,而在根本不打算显示的情况下再次消失。因此,更好的策略是默认情况下将其隐藏,并在确定资源可用性后立即将其呈现。

function ready () {
  let anl_toTest = Array.from ( document.querySelectorAll ( '.fa-sign-x' ) )
    ;
  
  anl_toTest.forEach ( (e_span) => {
    let myRequest = new Request ( e_span.parentNode.href)
      ;
     
    // Fetch API. See [this MDN section](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) for details and code samples  
    fetch(myRequest)
      .then (
          function(response) {
            if (response.ok) { // Resource was successfully retrieved, show the link 
              e_span.style.display = "inline";
            }
          }
        , function (e) {
            console.log(`Failed on '${myRequest.url}': ${e.message}.`);
          }
      );
   });
} // ready

window.addEventListener ( 'load', ready );
.fa-sign-x {
  display: none;
}
<a href="https://www.gravatar.com/avatar/00000000000000000000000000000000?d=identicon&f=y"  data-lightbox="kumas" data-title="Pattern" class="tab active"  >
   <span  class="fa-sign-x" >Pattern</span>
</a>&nbsp;
<a href="https://www.example.com/whatever.jpg"  data-lightbox="kumas" data-title="Failed" class="tab active"  >
   <span  class="fa-sign-x" >Failed</span>
</a>&nbsp;
<a href="https://secure.gravatar.com/avatar/1a0ea6b0656f0af322419bd6a607598f?s=100&d=retro&r=g"  data-lightbox="kumas" data-title="Polar Bear" class="tab active"  >
   <span  class="fa-sign-x" >Polar Bear</span>
</a>

0
投票

您可以使用file_exists()功能检查文件是否存在。

if(file_exists("/sunsetplanlama/".$sonuc['proje_ismi']."/kumas_1.png")){
    echo '<a href="/sunsetplanlama/'.$sonuc['proje_ismi'].'/kumas_1.png"  data-lightbox="kumas" data-title="'.$sonuc['proje_ismi'].'" class="tab active" >K1</a>';
}
© www.soinside.com 2019 - 2024. All rights reserved.