2012-07-31 25 views
0

您好我有以下代码:的jQuery的preventDefault

collapsed.on('click', 'a',function(c) { 
    c.preventDefault(); 
}); 

倒塌基本上是一个div元素,这里面的div有它,因为它代表它不会因为防止功能的工作,一个锚标记。防止功能需要在那里。即使使用preventDefault函数,是否有办法让该标签在该div内工作?

让我知道你是否需要更多信息。

+0

嗯..好吧,你正在防止'a'上的默认动作,那么你期望发生什么? – 2012-07-31 16:28:45

+5

默认情况下,如果您确实希望默认工作,那么阻止默认设置的意义何在? – Rooster 2012-07-31 16:28:56

+0

为什么预防需要在那里? – 2012-07-31 16:29:04

回答

0

这将发送用户的快乐方式。

collapsed.on('click', 'a',function(c) { 
    c.preventDefault(); 
    window.location = this.href 

    /* 
     other options include: 
     window.location = $(this).attr('href'); 
     window.location = this.getAttribute('href'); 
     window.location = 'http://staticurl.com'; 
    */ 
}); 

我怀疑你的标记有一个设计缺陷,尽管...如果你发布了,也许你可以避免你的链接上的preventDefault。

0

问题解决了......我没有在“折叠”(这是手风琴中的一个封闭div)上应用点击事件,而是在一般的手风琴div上应用了click事件。

谢谢你们