首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.on(‘单击’)绑定不起作用的JQuery stopPropogation

.on(‘单击’)绑定不起作用的JQuery stopPropogation
EN

Stack Overflow用户
提问于 2017-04-04 01:22:56
回答 1查看 62关注 0票数 0

我试图阻止按钮单击冒泡到表格行事件,但我似乎无法阻止它的发生。

因此,基本上,我有一个表行,它可以单击,并将您带到不同的屏幕。

我的行上有一个按钮,它执行下面的函数,通过AJAX返回数据,并刷新页面。

下面是按钮的JQuery函数:

代码语言:javascript
复制
$('#check_container').on('click', '.edit-risk-compliance', function(e) {

    e.preventDefault(); // tried this on its own, and together with below
    e.stopPropagation(); // tried this on its own, and together with below
    e.stopImmediatePropagation(); // tried this on its own, and together with below

    // capture course_id from clicked button
    var risk_type_id = $(this).attr('id');

    // change type 1 = exclude, change type 2 = include
    var change_type = $(this).data('id');

    $.ajax({
        type: "POST",
        url: base_url + 'risk/amend_risk_compliance',
        data: "risk_type_id=" + risk_type_id + "&change_type=" + change_type,
        success: function (data) {

            $('#check_container').html(data);

        }
    });

});

以下是用于行单击的函数:

代码语言:javascript
复制
$('#table_holder').on('click', '.risk_log_row', function() {
    // capture risk_type_id from clicked button
    var risk_type = $(this).attr('id');
    // redirect to controller to show privileges
    window.location = '/risk/manage_questions/' + risk_type;
});

下面是我的html:

代码语言:javascript
复制
    <div class="row" id="check_container">
        <div id='table_holder' class="col-md-12" >
            <table id="risk_log_table" class="sortable table table-striped tablesorter">                                        
                <thead>
                    <tr>
                        <th>Risk Assessment</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody> 
                    <tr id='4' class='risk_log_row clickable'>
                        <td data-title='Risk Assessment'>Agency Workers</td>
                        <td data-title='Actions'>
                            <div id='4' data-toggle='tooltip' title='Edit risk renewal period' class='edit-freq-btn btn risk-btns btn-info btn-sm'>Edit Renewal</div>
<div id='2' data-id='2' data-toggle='tooltip' title='Include in compliance' class='edit-risk-compliance btn btn-primary btn-sm'>In compliance?</div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
EN

回答 1

Stack Overflow用户

发布于 2017-04-19 22:31:12

更改将单击事件附加到按钮的方式,如

代码语言:javascript
复制
$('.edit-risk-compliance').on('click',  function(e) {
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43190714

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档