我的 HTML div 中有一个类标签和一个有 2 个看起来像一个类的类。
<body>
<div class="ad-container left">
<div class="ad-container">
<div class="mobile-ad larger">
<div class="mobile-ad">
</body>
在 jQuery 中使用 not 选择器以支持所有 4 个 div 并且不忽略正文中的任何其他内容的正确方法是什么。
我现在有
$('body:not(.ad-container,.ad-container.left,.mobile-ad.larger,.mobile-ad)')
它似乎没有任何问题。
但有些东西告诉我,我需要用逗号将左边的类和较大的类分成单独的元素。
像这样
$('body:not(.ad-container,.left,.mobile-ad,.larger)')
完整代码如下:
$(function () {
$('body:not(.ad-container,.ad-container.left,.mobile-ad.larger,.mobile-ad)').on('selectstart', function (event) {
event.preventDefault();
});
});
它用于禁用左键双击选择但仍然可以点击广告。 我应该使用哪一个?
最佳答案
我最终使用了
$('body :not(.ad-container, .mobile-ad)')
关于javascript - 如何在将多个类作为一个类的jquery中使用not选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22125571/