Really simple jquery question here that I have yet to resolve. I have the following html table

我还没有解决这个简单的jquery问题。我有下面的html表格

<table id="table-1">
    <tr>
        <td>Value 1</td>
        <td>Value 2</td>
        <td>
            <button id="btn-1" value="Go"></button>
        </td>
    </tr>
</table>

I have the following event listener for when the table row is clicked

当单击表行时,我有以下事件监听器

$("table-1 tr").on(
   'click',
    function(e){
       if(button was clicked){ 
           //do some stuff 
       } else {
           //do different stuff
       }
    }
);

I'd like this event listener to fire whenever the table row is selected, except for when the clicked item is my button. I've been trying to use :not and .not(), but no luck. Any ideas?

当选择表行时,我希望这个事件监听器可以触发,但是当单击的项是我的按钮时除外。我一直试着用:不,不是(),但没有运气。什么好主意吗?

4 个解决方案

#1


3

Based off your example where you want to catch the element type.

基于要捕获元素类型的示例。

$("#table-1 tr").on('click', function (e) {
    var elementType = $(e.target).prop('nodeName');
    if (elementType == 'BUTTON') {
        console.log('buttonClick');
    } else {
        console.log(elementType);
    };
});

http://jsfiddle.net/ymy9cn71/

http://jsfiddle.net/ymy9cn71/

更多相关文章

  1. jQuery -添加活动类并在单击时从其他元素中删除活动类
  2. 确定焦点事件:单击或tabstop
  3. 单击文件输入后,Fancybox正在关闭
  4. 如何使用jQuery捕获对href值的单击
  5. 单击列表项时如何编写内容? [重复]
  6. 如何通过多次单击在画布上显示多个箭头
  7. 单击链接中的复选框会导致以下链接——我如何避免这种情况?
  8. 我无法理解为什么我的代码中的单击选择文本
  9. 当锚标记被单击时,角值从一个页面传递到另一个页面

随机推荐

  1. android listview多视图嵌套多视图
  2. Android高可拓展框架Conductor源码解析(2
  3. Android动画精讲一:从setTranslationX谈属
  4. 安卓中MVC模式的深度思索和实践(二)
  5. Android 通知(Notification)的基本用法
  6. 使用Kotlin开发Android项目-Kibo(二)
  7. 背景图像颜色检测与Android油漆。
  8. IDEA简介和快捷键设置
  9. Android控件之Dialog(two)列表与自定义弹
  10. 在Activity中添加Fragment