【问题标题】:JQuery Internal does not work [closed]JQuery内部不起作用[关闭]
【发布时间】:2013-01-24 02:05:52
【问题描述】:

这是我的 javascript 代码

$(this).find('a:internal:not(.no-ajaxy)').on('click',function(evt) {
        evt.preventDefault();
        History.pushState(null, $(this).text(), $(this).attr('href'));
    });

这是我试图在

上不应用 ajax 的链接
 <a href="#loginModal" class="btn btn-success no-ajaxy" data-toggle="modal">Login &rsaquo;&rsaquo;</a>

这里的问题是我的脚本给了我这个错误

Uncaught Error: Syntax error, unrecognized expression: unsupported pseudo: internal 

我目前正在使用 jQuery v1.8.3

【问题讨论】:

  • 没有:internal 选择器,所以我不确定您要在这里做什么?
  • 我正在尝试选择类名中包含 no-ajaxy 的所有 href 标记
  • $(this).find('a.no-ajaxy').on(... 虽然你所说的你想要的与你的代码似乎试图做的完全相反。
  • 如果类名类似于 class="btn btns-submit no-ajaxy" 会起作用吗?
  • $(this).find('a:not(.no-ajaxy)') 所有这些都在api.jquery.com 的选择器部分 - 我建议你阅读它。

标签: javascript jquery ajax dom internal


【解决方案1】:

从您的 cmets 看来,您只需要使用以下内容:

$(this).find('a:not(.no-ajaxy)').on('click', function() {
     // your code...
});

:internal 不是 jQuery 中默认可用的选择器。

【讨论】:

    【解决方案2】:

    我认为您必须创建自定义选择器(http://dpatrickcaldwell.blogspot.ch/2010/03/custom-jquery-selector-for-external-and.html 的副本):

    jQuery.extend(  
      jQuery.expr[ ":" ],  
      {  
        /* 
          /:\/\// is simply looking for a protocol definition. 
          technically it would be better to check the domain 
          name of the link, but i always use relative links 
          for internal links. 
        */  
    
        external: function(obj, index, meta, stack)  
        {  
          return /:\/\//.test($(obj).attr("href"));  
        },  
    
        internal: function(obj, index, meta, stack)  
        {  
          return !/:\/\//.test($(obj).attr("href"));  
        }  
      }  
    );  
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-06
      • 2018-05-09
      • 2016-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多