Home > Web Front-end > JS Tutorial > body text

How to control a tag to be non-clickable in jquery

coldplay.xixi
Release: 2020-11-19 16:44:40
Original
7059 people have browsed it

Jquery method to control the a tag not being clickable: 1. Remove the href attribute in the a tag, the code is [$('.disableCss').removeAttr('href')]; 2. Add the disabled attribute, The code is [attr('disabled',"true")].

How to control a tag to be non-clickable in jquery

jquery method to control a tag not clickable:

jquery disable a tag method 1

$(document).ready(function () {
        $("a").each(function () {
            var textValue = $(this).html();
            if (textValue == "XX概况" || textValue == "服务导航") {
                $(this).css("cursor", "default");
                $(this).attr(&#39;href&#39;, &#39;#&#39;);     //修改<a>的 href属性值为 #  这样状态栏不会显示链接地址  
                $(this).click(function (event) {
                    event.preventDefault();   // 如果<a>定义了 target="_blank“ 需要这句来阻止打开新页面
                });
            }
        });
});
Copy after login

jquery disable a tag method 2

$(&#39;a.tooltip&#39;).live(&#39;click&#39;, function(event) {
   alert("抱歉,已停用!");  
  event.preventDefault();   
});
Copy after login

jquery disable a tag method 3

$(function(){
$(&#39;.disableCss&#39;).removeAttr(&#39;href&#39;);//去掉a标签中的href属性
$(&#39;.disableCss&#39;).removeAttr(&#39;onclick&#39;);//去掉a标签中的onclick事件
});
Copy after login

jquery Disabling and enabling control buttons

The control button is disabled:

$(&#39;#button&#39;).attr(&#39;disabled&#39;,"true");添加disabled属性 
$(&#39;#button&#39;).removeAttr("disabled"); 移除disabled属性
Copy after login

Related free learning recommendations:JavaScript(video)

The above is the detailed content of How to control a tag to be non-clickable in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template