Jquery 多个 'a' 选择器 .not causing "Syntax error, unrecognized expression"

Jquery multiple 'a' selectors with .not causing "Syntax error, unrecognized expression"

对于带有 jquery 1.8 的 "click" 函数,我有此代码

  $(document).ready(function(){

    var siteURL = "http://http://whosebug.com";
      
    var $internalLinks = $("a[href^='"+siteURL+"'], a[href^='/'], a[href^='./'], a[href^='../'], a[href^='#'], .loader[onclick]:not(#external)");

    var $excludeIntern = $('a[target=_blank], a[href*="vcf"], .no-ajaxy, a[href*="wp-login"], a[href*="wp-admin"], a[href*="gif"]');
           
    $internalLinks = $internalLinks.not($excludeIntern);

    $internalLinks.live('click', function(event){alert("ok");})
                        
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
  <a href="#test">link1</a>
    <a href="/test">link2</a>
    <a href="/test" target="_blank">link3</a>
    <a href="http://google.de">link4</a>

这导致:

"Syntax error, unrecognized expression".

没有 .not 选择器它可以工作,但我需要从这个函数中排除一些链接。

有人知道为什么吗?

从 jQuery 版本 1.7 开始,.live() 方法已弃用。 尝试使用 .on() 来将事件处理程序附加到匹配的元素:

 $internalLinks.on('click', function(event){
   alert("ok");
 });

Demo