本文摘自PHP中文网,作者藏色散人,侵删。
jquery让a不跳转的实现方法:1、通过“event.preventDefault();”语句阻止打开新页面;2、通过live方法禁用a标签;3、去掉a标签中的href属性以及onclick事件。

本教程操作环境:windows10系统、jquery2.2.4,本文适用于所有品牌的电脑。
推荐:《jquery视频教程》
jQuery控制a标签不可点击 不跳转
jquery禁用a标签方法1
1 2 3 4 5 6 7 8 9 10 11 12 | $(document).ready( function () {
$( "a" ).each( function () {
var textValue = $(this).html();
if (textValue == "XX概况" || textValue == "服务导航" ) {
$(this).css( "cursor" , "default" );
$(this).attr( 'href' , '#' );
$(this).click( function (event) {
event.preventDefault();
});
}
});
});
|
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' );
$( '.disableCss' ).removeAttr( 'onclick' );
});
|
jquery控制按钮的禁用与启用
控制按钮为禁用:
1 2 | $( '#button' ).attr( 'disabled' , "true" );添加disabled属性
$( '#button' ).removeAttr( "disabled" ); 移除disabled属性
|
相关免费学习推荐:JavaScript(视频)
以上就是jquery 怎么让a不跳转的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
jQuery怎样判断属性是否存在
jQuery对象和dom对象之间的差异
jQuery表单插件jQuery.form.js
jQuery怎么获取html元素的内容?
bootstrap 5 alpha发布啦!不再依赖jQuery,放弃支持ie
jQuery如何让select不可用
jQuery框架和bootstrap框架区别
jQuery和zepto是什么?
jQuery怎么去除css属性
jQuery怎么实现奇偶行不同颜色
更多相关阅读请进入《jQuery》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » jquery 怎么让a不跳转