如何限制应用于< body>的点击事件从在正文中的jquery数据表上执行 [英] how to limit a click event applied to the <body> from executing on a jquery datatable in the body

查看:65
本文介绍了如何限制应用于< body>的点击事件从在正文中的jquery数据表上执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有动画数据表,当点击它们的超链接时,它会从左侧滑入。当用户完成读取可见数据表的内容时,我应用以下代码以允许用户在其他任何地方点击以将表停放并继续查看。我使用jQuery代码来附加click事件......

I have animated datatables which slide in from the left when their hyperlink is clicked. And when the user is done reading the contents of the visible datatable, I applied the following code to allow the user to click anywhere else to park the table away and proceed with viewing. I used jQuery code for attaching the click event...

<script type="text/javascript" charset="utf-8">
    $(document).ready( function () {$('.dtable').dataTable( {"sDom": 'rt',"sScrollY":"200px", "bPaginate":false, "bFilter":false} );**$('body').click(function() {parkDataTables();});})
</script>

不幸的是,点击数据表本身会将其停放。我不希望这种行为。也许有人知道如何阻止这个点击事件在数据表面上触发......

Unfortunately, clicking on the datatable itself parks it. And I don't want that behavior. Maybe someone has an idea on how to block this click event from firing on the surface of the datatable...

非常感谢

Dennis

推荐答案

你应该用

$('.dtable').click(function(){return false;});

问题是,当您点击表格时,事件首先进入表格然后它传播给父母(最后到正文,当 parkDataTables 被捕获。)

The problem is that when you click on the table, the event goes into the table first and then it propagates to the parents (and finally to the body, when the parkDataTables is catched).

您也可以使用 stopPropagation 代替( http://api.jquery.com/event.stopPropagation/ ),因为返回false 您还可以停止表格上的默认点击行为。

You could also use stopPropagation instead ( http://api.jquery.com/event.stopPropagation/ ), because with the return false you also stop the default click behavior on the table.

$('.dtable').click(function(event){
    event.stopPropagation();
});  

也许您可以查看此页面以查看最后的差异: http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/

Maybe you could check this page to see this last difference: http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/

这篇关于如何限制应用于&lt; body&gt;的点击事件从在正文中的jquery数据表上执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆