Home  >  Article  >  Web Front-end  >  jquery a tag is not available implementation method

jquery a tag is not available implementation method

藏色散人
藏色散人Original
2020-12-08 10:05:061987browse

jquery How to implement the unavailable a tag: First create a sample file; then use jQuery to make the a tag unavailable, with statements such as "if (boolean) {$("a").attr( "disabled", true)...}".

jquery a tag is not available implementation method

The operating environment of this tutorial: windows7 system, jquery1.10.0 version, Dell G3 computer. This method is suitable for all brands of computers.

Recommendation: "jquery video tutorial" "javascript basic tutorial"

##jquery makes a tag unavailable

Sometimes, we need to make the a tag unavailable under certain conditions. However, due to the special nature of the a tag, just adding the disabled attribute to it can only make it gray, and it will still jump when clicked. transfer, so other processing is required.

Here is a method of using jQuery to make a tag unavailable:

if(boolean){
    $("a").attr("disabled", true);
    $("a").click(function(){});
}

In fact, it is to gray out the tag and set its jump function to empty, native JS and other frameworks can be implemented by referring to this method.

or

$("a").attr("disabled", true);
$('.disableCss').removeAttr('href');//去掉a标签中的href属性
$('.disableCss').removeAttr('onclick');//去掉a标签中的onclick事件

If there is a data-toggle switch attribute of the tab page, you need to add a $(".disableCss").removeAttr('data-toggle');

The above is the detailed content of jquery a tag is not available implementation method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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