Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery不使用我的html_Jquery - Fatal编程技术网

jquery不使用我的html

jquery不使用我的html,jquery,Jquery,可能重复: 我有这个HTML代码 <div id="nav-bar"> <span> <a href="check.html">check</a> </span> </div> 您应该使用获取: 您应该使用获取: 您不需要.find()也不需要e.preventDefault()。(显然,您不需要.filter() $('div#导航栏a')。单击(函数(){ var u

可能重复:

我有这个HTML代码

<div id="nav-bar">  
  <span>  
        <a href="check.html">check</a>  
      </span>  
</div>
您应该使用获取

您应该使用获取

您不需要
.find()
也不需要
e.preventDefault()
。(显然,您不需要
.filter()


$('div#导航栏a')。单击(函数(){
var url=$(this.data('url');
window.location.href=url;
});
您不需要
.find()
也不需要
e.preventDefault()
(显然您不需要
.filter()


$('div#导航栏a')。单击(函数(){
var url=$(this.data('url');
window.location.href=url;
});

您误用了
.filter()
。这是为了缩小jQuery对象的选择范围。
.find()
将在jQuery对象的元素中查找匹配的元素(因此
$('div#导航栏')。find('a')
将在
元素中查找

但是,如果直接使用直接选择器,您也会发现更好的里程数:

$('#nav-bar a').click(function (e) {
    e.preventDefault();
});

选择器
#nav bar a
选择
#nav bar
元素中的所有
元素。

您误用了
.filter()
。这是为了缩小jQuery对象的选择范围。
.find()
将在jQuery对象的元素中查找匹配的元素(因此
$('div'nav bar')。find('a')
将在
元素中查找

但是,如果直接使用直接选择器,您也会发现更好的里程数:

$('#nav-bar a').click(function (e) {
    e.preventDefault();
});

选择器
#nav bar a
选择
#nav bar
元素中的所有
元素。

也许您想要代替
.filter()
?尝试用
查找
替换
过滤器
!我想我以前也看到过同样的问题..我的应用程序,先生,我没有看到这个问题。我现在如何关闭它?不要用全局
事件
对象损坏
事件
。使用
e
香蕉
或其他任何东西。你还可以说明你为什么要尝试吗要做到这一点?这会给你的问题增加一些分量,并防止它被关闭。也许你希望使用而不是
.filter()
?尝试用
查找
替换
过滤器
!我想我以前也看到过同样的问题..我的应用程序,先生,我没有看到这个问题。我现在如何关闭它?不要用全局
事件
对象损坏
事件
。使用
e
香蕉
或其他任何东西。你还可以说明你为什么要尝试吗要做到这一点?这会给你的问题增加一些分量,并防止问题被关闭。你的代理签名是向后的。它应该是
$('#导航栏')。在('click','a',function(event){});
上,你的代理签名是向后的。它应该是
$('#导航栏')。在('click','a',function(event){})上
如果没有JS,这将如何处理?@devdigital:Hmmm.Point.不太优雅的降级?:)但是,一开始就毫无进展的链接有什么意义呢?.OP没有提到。如果没有JS,这将如何处理?@devdigital:Hmmm.Point.不太优雅的降级?:)但是,一开始就不存在的链接有什么意义呢?OP没有提到。
$('#nav-bar a').click(function(event) {
    event.preventDefault();
});
$('#nav-bar a').click(function(event){
    event.preventDefault();
});  
$('#nav-bar').on("click", "a", function(event){
    event.preventDefault();
});
<div id="nav-bar">  
  <span>  
        <a href="#" data-url="check.html">check</a>  
      </span>  
</div>



$('div#nav-bar  a').click(function(){
   var url = $(this).data('url');
   window.location.href = url;
});
$('#nav-bar a').click(function (e) {
    e.preventDefault();
});