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 - JQuery events cause page reload. How to fix? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JQuery events cause page reload. How to fix? - Stack Overflow

programmeradmin3浏览0评论

I'm observing a behavior where onClick events cause a page to reload.

$('#target').click(function(){
    $('#target').hide();
})

So the object is shown, it hides on click, but then page reloads and the object is shown again. I'm working on a website that was setup before me, so I'm not entirely aware of all its parts. Any idea what might cause this behavior and how to fix it?

I'm observing a behavior where onClick events cause a page to reload.

$('#target').click(function(){
    $('#target').hide();
})

So the object is shown, it hides on click, but then page reloads and the object is shown again. I'm working on a website that was setup before me, so I'm not entirely aware of all its parts. Any idea what might cause this behavior and how to fix it?

Share Improve this question edited Apr 8, 2013 at 21:20 Evan Davis 36.7k7 gold badges52 silver badges58 bronze badges asked Apr 8, 2013 at 21:13 skyisredskyisred 7,1156 gold badges41 silver badges56 bronze badges 1
  • How is this marked with a php tag? – AlbertEngelB Commented Apr 8, 2013 at 21:15
Add a ment  | 

2 Answers 2

Reset to default 7

You need to prevent the default event behavior with event.preventDefault:

$("#target").on("click", function (e) {
    $(this).hide();
    e.preventDefault();
});

Using return false will also work, but it does more than you may intend.

This is in line with the event cancellation standard

add a

return false;

as last statement so that the link is not called, only you function (onclick) is executed.

发布评论

评论列表(0)

  1. 暂无评论