簡體   English   中英

禁用嵌套 HTML 中的所有鏈接

[英]Disable all links in nested HTML

我的 html 代碼中有這個片段

<nav>        
    <ul class="test-list test-list-level-1">            
        <li class="test-page-1 test-heading-level-2">                
            <a class="test-link test-heading-1" href="#L1" title="t1">T1</a>            
        </li>            
        <li class="test-page-1 test-heading-level-2">                
            <a class="test-link test-heading-2" href="#L2" title="t2">T2</a>                
            <ul class="test-list-level-3">                    
                <li class="test-heading-level-3">                        
                    <a class="test-link test-heading-3" href="#L3" title="t3">T3</a>                    
                </li>                
            </ul>            
        </li>             
    </ul>    
</nav>

我的目標是將每個 href 設置為 "" 以禁用鏈接。

我試過了

<script type='text/javascript'>
$("a.test-link").removeAttr('href');
</script>

但是什么也沒發生。

我將其設置為頁腳和 header。

編輯:我通過包圍它來解決它

jQuery(function($){
                $("a.test-link").removeAttr('href');
            });

你試過這樣嗎:

$("a.test-link").removeAttribute("href")

在 jquery 中使用此代碼。

jQuery(function($){
  $("a.test-link").click(function(e){
    e.preventDefault();
  });
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM