return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - Both event.preventDefault() and event.returnValue = false don't work in Firefox - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Both event.preventDefault() and event.returnValue = false don't work in Firefox - Stack Overflow

programmeradmin3浏览0评论

I have tried these to snippets of codes, the first one works in IE and Chrome, the second one works in Chrome only, but both of them don't work in Firefox. What I want is to stop the page from going to other pages via links

$('.album a').click(function(){
    event.returnValue = false;
    //other codes
})

$('.album a').click(function(){
    event.preventDefault();
    //other codes
})

Edit: This snippet from Ian worked for me

$('.album a').click(function(e){
    e.preventDefault();
    //other codes
});

I have tried these to snippets of codes, the first one works in IE and Chrome, the second one works in Chrome only, but both of them don't work in Firefox. What I want is to stop the page from going to other pages via links

$('.album a').click(function(){
    event.returnValue = false;
    //other codes
})

$('.album a').click(function(){
    event.preventDefault();
    //other codes
})

Edit: This snippet from Ian worked for me

$('.album a').click(function(e){
    e.preventDefault();
    //other codes
});
Share Improve this question edited Jul 24, 2013 at 23:54 Andrew Liu asked Jul 18, 2013 at 0:59 Andrew LiuAndrew Liu 2,5485 gold badges23 silver badges29 bronze badges 1
  • 1 You might consider not using a-links, particularly as you are not using them as links. You can use another element (span, etc.) and, if you want to, use css to make it look like a link. – Andy G Commented Jul 18, 2013 at 1:04
Add a ment  | 

3 Answers 3

Reset to default 4

You need to provide the Event parameter:

$('.album a').click(function(e){
    e.preventDefault();
    //other codes
});

You don't need to deal with returnValue, as jQuery normalizes the method to work across browsers, by only calling preventDefault.

Note how the handler in the docs show this eventObject as the parameter passed to it: http://api.jquery./click/

And note how the Event object has the preventDefault method: http://api.jquery./category/events/event-object/

Your callback signature does not register the event argument. Therefor your callbacks do not have access to the event object, and cannot prevent it.

$('.album a').click(function(event){
    event.returnValue = false;
    //other codes
});

$('.album a').click(function(event){
    event.preventDefault();
    //other codes
});

Try changing your code to the following:

$('.album a').click(function(e){
    e.preventDefault();
    return false;
})
发布评论

评论列表(0)

  1. 暂无评论