js 获取列表中的chekbox的值, 并获取同一个行列表中相应的值

点击商品时把已选择的id 和标题获取到js中

廖圣平博客

        function add_selected_goods(obj) {
            var select_html = '';
            var selected_goods_ids = new Array();
            $('#select-goods-table tbody').find("input[type='checkbox']").each(function () {
                var is_selected = $(this).is(':checked');
                if (is_selected) {
                    var tr_obj = $(this).parent().parent();
                    let goods_id = $(tr_obj).find('.select-goods-goods-id').html();
                    var goods_title = $(tr_obj).find('.select-goods-title').html();
                    var goods_number = $(tr_obj).find('.select-goods-number').html();
                    var flag = $.inArray(goods_id, selected_goods_ids);
                    if (flag === -1) {
                        $('.selected-goods-id').each(function () {
                            let selected_goods_id = $(this).val();
                            if (selected_goods_id === goods_id) {
                                flag = false;
                            }
                        });
                    }
                    if (flag) {
                        selected_goods_ids.push(goods_id);
                        select_html += '<tr>';
                        select_html += '<td><input type="hidden" class="selected-goods-id" value="' + goods_id + '">' + goods_id + '</td>';
                        select_html += '<td>' + goods_title + '</td>';
                        select_html += '<td style="width: 80px;">';
                        select_html += '<a href="javascript:void(0);" class="list-operate js-confirm" onclick="delete_selected_product(this)">删除</a>';
                        select_html += '</td>';
                        select_html += '</tr>';
                    }
                }
            });
            $('#selected-goods-tbody').append(select_html);
            $(".mask").fadeOut();
            $(".detail").fadeOut();
        }

猜你喜欢

转载自blog.csdn.net/qq_22823581/article/details/80450647
今日推荐