【发布时间】:2021-03-10 12:19:57
【问题描述】:
绅士你好
1°请问如何通过css类禁用点击行为onclick?
2° 我不能在 HTML 元素中使用 ID,因为我无法在代码中插入任何 ID,所以我需要使用 Class 来实现魔法。
3°在我所有的尝试中,没有一个仍然有效。
点击后我需要禁用的元素和 CSS 类:
<label class="inner all disabled reserved my_numbers">
<span class="p5_effect_tooltip_b top">
<span class="numero">999999<br><small>pending<br>payment</small></span>
<span class="p5_custom_tooltip_b">Pre-Reserved: Jim</span>
</span>
</label>
班级:label.inner.all.disabled.reserved.my_numbers
1°第一次尝试:
jQuery(document).ready(function() {
$("#inner.all.disabled.reserved").click(function() {
return false;
});
});
2° 第二次尝试:
$(document).ready(function() {
$(".label.inner.all.disabled.reserved").click(function() {
$("label").off("click");
});
});
3° 第三次尝试:
$(document).ready(function() {
$("#inner.all.disabled.reserved").click(function() {
return false;
});
});
4°尝试:
$('#inner.all.disabled.reserved.my_numbers').disabled = true
【问题讨论】:
-
要禁用仅使用 CSS 的点击,请尝试
pointer-events: none; -
inner.all.disabled.reserved- 这是类,但您指定为 id -
查看浏览器开发工具控制台上出现的任何错误消息。
-
@ozgur,感谢您的帮助.....但是我必须禁用单击行为并保持悬停行为。鼠标悬停在元素上时,工具提示必须继续工作。有了这个指针事件属性,所有的悬停事件都将被禁用。
-
@PaulodoPorto 对不起,我没有注意到悬停的必要性
标签: javascript html jquery css jquery-ui