jQuery控制a標簽不可點擊 不跳轉


jquery禁用a標簽方法1

01
02
03
04
05
06
07
08
09
10
11
12
$(document).ready( function () {
         $( "a" ).each( function () {
             var textValue = $( this ).html();
             if (textValue == "XX概況" || textValue == "服務導航" ) {
                 $( this ).css( "cursor" , "default" );
                 $( this ).attr( 'href' , '#' );     //修改<a>的 href屬性值為 #  這樣狀態欄不會顯示鏈接地址 
                 $( this ).click( function (event) {
                     event.preventDefault();   // 如果<a>定義了 target="_blank“ 需要這句來阻止打開新頁面
                 });
             }
         });
});

jquery禁用a標簽方法2

1
2
3
4
$( 'a.tooltip' ).live( 'click' , function (event) {
    alert( "抱歉,已停用!" ); 
   event.preventDefault();  
});

jquery禁用a標簽方法3

1
2
3
4
$( function (){
$( '.disableCss' ).removeAttr( 'href' ); //去掉a標簽中的href屬性
$( '.disableCss' ).removeAttr( 'onclick' ); //去掉a標簽中的onclick事件
});

jquery控制按鈕的禁用與啟用

控制按鈕為禁用:

1
2
$( '#button' ).attr( 'disabled' , "true" );添加disabled屬性
$( '#button' ).removeAttr( "disabled" ); 移除disabled屬性


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM