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

我在隐藏空链接时遇到问题。请有人帮助我。:


<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"信之外别无他法......


我怎样才能做到这一点?


www说
浏览 155回答 2
2回答

凤凰求蛊

需要考虑的几点:服务器端解决方案是不合适的:您想在客户端测试资源可用性,而这只能通过客户端作为代理来实现。检查资源可能需要时间,特别是比在客户端呈现 html 所需的时间更多。在检索资源失败的情况下删除可见标记(例如span示例的元素)可能会导致呈现的材料短暂显示并再次消失,而意图根本不显示它。因此更好的策略是默认隐藏它并在确定资源可用性后立即显示它。function ready () {&nbsp; let anl_toTest = Array.from ( document.querySelectorAll ( '.fa-sign-x' ) )&nbsp; &nbsp; ;&nbsp;&nbsp;&nbsp; anl_toTest.forEach ( (e_span) => {&nbsp; &nbsp; let myRequest = new Request ( e_span.parentNode.href)&nbsp; &nbsp; &nbsp; ;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; // Fetch API. See [this MDN section](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) for details and code samples&nbsp;&nbsp;&nbsp; &nbsp; fetch(myRequest)&nbsp; &nbsp; &nbsp; .then (&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; function(response) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (response.ok) { // Resource was successfully retrieved, show the link&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e_span.style.display = "inline";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; , function (e) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(`Failed on '${myRequest.url}': ${e.message}.`);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; );&nbsp; &nbsp;});} // readywindow.addEventListener ( 'load', ready );.fa-sign-x {&nbsp; display: none;}<a href="https://www.gravatar.com/avatar/00000000000000000000000000000000?d=identicon&f=y"&nbsp; data-lightbox="kumas" data-title="Pattern" class="tab active"&nbsp; >&nbsp; &nbsp;<span&nbsp; class="fa-sign-x" >Pattern</span></a>&nbsp;<a href="https://www.example.com/whatever.jpg"&nbsp; data-lightbox="kumas" data-title="Failed" class="tab active"&nbsp; >&nbsp; &nbsp;<span&nbsp; class="fa-sign-x" >Failed</span></a>&nbsp;<a href="https://secure.gravatar.com/avatar/1a0ea6b0656f0af322419bd6a607598f?s=100&d=retro&r=g"&nbsp; data-lightbox="kumas" data-title="Polar Bear" class="tab active"&nbsp; >&nbsp; &nbsp;<span&nbsp; class="fa-sign-x" >Polar Bear</span></a>

慕盖茨4494581

您可以使用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>'; }
打开App,查看更多内容
随时随地看视频慕课网APP