当单击行内的按钮时,防止表行单击事件触发 [英] Prevent table row onclick event to fire when clicking button inside the row

查看:85
本文介绍了当单击行内的按钮时,防止表行单击事件触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表行与ONCLICK事件(切换下面的附加数据)。在一行行单元格中,我有一个按钮(当单击执行AJAX操作时)。
当我点击按钮 - Row的onclick事件也触发,发生什么事情是附加数据在AJAX调用完成之前出现(这对我来说是一个不好的行为)。
任何想法如何才能优雅地解决这个问题? (没有识别和编码到行的onclick代码)
谢谢

解决方案

添加一个 event.stopPropagation(); 到您的按钮单击处理程序。有关详细信息,请查看此处 here


I have a table row with ONCLICK event (that toggles additional data below). Inside one of the row cells I have a button (when clicked is performing an AJAX action). When I click on the button - the Row's onclick event also fires and what happens is that the additional data appears before the AJAX call completes (which is a bad behavior for me). Any ideas how can I solve this elegantly? (without identifying and coding it into the row's onclick code) Thanks

解决方案

Add an event.stopPropagation(); to your buttons click handler. For more information, have a look here and here.

这篇关于当单击行内的按钮时,防止表行单击事件触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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