How to prevent a from jumping in jquery

藏色散人
Release: 2020-11-30 14:50:12
Original
3821 people have browsed it

How to implement jquery to prevent a from jumping: 1. Prevent the opening of a new page through the "event.preventDefault();" statement; 2. Disable the a tag through the live method; 3. Remove the href in the a tag attributes and onclick events.

How to prevent a from jumping in jquery

The operating environment of this tutorial: windows10 system, jquery2.2.4, this article is applicable to all brands of computers.

Recommended: "jquery video tutorial"

jQuery controls the a tag to be non-clickable and non-jumping

jquery disables the a tag Method 1

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

jquery disables a tag Method 2

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

jquery disables a tag Method 3

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

Disabling and enabling jquery control button

Control button Disabled:

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

Related free learning recommendations:JavaScript(video)

The above is the detailed content of How to prevent a from jumping 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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!