jquery怎么禁止div

文章2022-03-04137 人已阅来源:网络

jquery禁止div的方法:1、使用JQuery的off()方法禁用div;2、使用JQuery结合CSS的“pointer-events: none;”实现禁用div即可。

jquery怎么禁止div

本文操作环境:windows7系统、jquery3.2.1版、DELL G3电脑

jquery怎么禁止div?

使用JQuery禁用div的两种方法

第一种方法:

使用JQuery的off()方法:

$('#example').off('click');

使用此方法后如果想重新启用,还要重新给'#example'添加绑定事件,即:

$('#example').on('click', function() {
    //...事件代码...
}

第二种方法:

使用JQuery结合CSS的'pointer-events: none;'实现:

.p-not-click {
    pointer-events: none;
}
// 禁用p
$('#example').addClass('select-not-click');

// 启用p
$('#example').removeClass('select-not-click');

个人推荐使用第二种

以上就是jquery怎么禁止div的详细内容!