javascript - 如何在模态 Bootstrap 中单击行表?

标签 javascript jquery twitter-bootstrap modal-dialog html-table

我在表中绑定(bind)了数据并在模式 Bootstrap 中显示它们。 我想使用单击或双击获取行表的数据,但它不起作用 enter image description here

   <div class="modal-body">
                <table id="table_search" class="table table-hover">
                    <thead>
                        <tr>
                            <td>CCA</td>
                            <td>Name</td>
                        </tr>
                    </thead>
                    <tbody>  
                    </tbody>
                </table>
            </div>

我使用jquery如下

 $('#table_search > tbody > tr').click(function () {
            alert( $(this).val());
        });

        $('#table_search > tbody > tr').dblclick(function () {
            alert($(this).val());
        });

但是它不起作用。

最佳答案

我认为您应该在此处使用事件委托(delegate)或附加事件 当显示模态时。另外 tr 没有您想要的文本值

$(document).on('click dblclick', '#table_search > tbody > tr', function (e) {
   alert($(this).text());
});

关于javascript - 如何在模态 Bootstrap 中单击行表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30218966/

相关文章:

Javascript - Google Chrome 不会更新 .js 文件

php - jscroll 结束时加载数据

javascript - 脚本 src 与页面代码中的脚本

html - 100 个表单元素水平展开 bootstrap

javascript - 在网页上添加多语言的更好方法

javascript - Bower 在运行 grunt serve 后抛出 jquery "not injected"警告

javascript - 使用 jQuery 键入时减小 TextArea 中文本的大小

jquery - $.ajaxPrefilter 覆盖请求正文

css - 打印时处理响应式媒体查询

javascript - Jquery ui 对话框按钮不适用于 bootstrap