jq拿不到tbody对象

$('#activityTable tbody').on('click', "input[type='radio']", function () {
                var activityId = $(this).val();
                var activityName = $(this).attr('activityName');
                $("#activityId").val(activityId);
                $("#create-activitySrc").val(activityName);
                $("#findMarketActivity").modal("hide");
            });

<!-- 查找市场活动 -->
<div class="modal fade" id="findMarketActivity" role="dialog">
    <div class="modal-dialog" role="document" style="width: 80%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">×</span>
                </button>
                <h4 class="modal-title">查找市场活动</h4>
            </div>
            <div class="modal-body">
                <div class="btn-group" style="position: relative; top: 18%; left: 8px;">
                    <form class="form-inline" role="form">
                        <div class="form-group has-feedback">
                            <input id="searchActivityNameTxt" type="text" class="form-control" style="width: 300px;"
                                   placeholder="请输入市场活动名称,支持模糊查询">
                            <span class="glyphicon glyphicon-search form-control-feedback"></span>
                        </div>
                    </form>
                </div>
                <table id="activityTable" class="table table-hover" style="width: 900px; position: relative;top: 10px;">
                    <thead>
                    <tr style="color: #B3B3B3;">
                        <td></td>
                        <td>名称</td>
                        <td>开始日期</td>
                        <td>结束日期</td>
                        <td>所有者</td>
                        <td></td>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

通过$('#activityTable tbody')拿不到,但是$('#activityTable')就可以,求解

已解决!!!

因为在动态填充数据如下

 success: function (res) {
                        var htmlStr = "";
                        $(res).each(function () {
                            htmlStr += "<tr><td><input type=\"radio\" name=\"activity\" activityName='" + this.name + "' value='" + this.id + "'/></td>";
                            htmlStr += "<td>" + this.name + "</td>";
                            htmlStr += "<td>" + this.startDate + "</td>";
                            htmlStr += "<td>" + this.endDate + "</td>";
                            htmlStr += "<td>" + this.owner + "</td></tr>";
                        });
                        $('#activityTable').html(htmlStr);
                          !!! 应该使用 $('#activityTable tbody').html(htmlStr);
                    }

不然使用tableid用html会重新创建tbody导致不一致。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值