jQuery : 如何用新元素替换元素并只显示新元素?

jQuery : How to replace an element with a new and only show the new one?

在以下代码中,当管理员编辑订单时,我会在 opencart 的管理面板中显示 order_status。订单状态显示完全正常。

            <?php if ($info_data['order_status']) { ?>
                <tr>
                <td><?php echo $info_data['text_order_status'];?</td>
                <td id="order-status"><?php echo $info_data['order_status']; ?></td>
                </tr>
            <?php } ?>

但是当管理员通过 selecting 从下拉列表中更新 order_status 时,它会显示更新后的 order_status 和旧的 order_status。我只需要显示更新后的 order_status ,如何用更新后的 order_status 替换旧状态?

if (json['success']) {
                    $('#history').load('index.php?route=sale/order/history&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>&shipping_code=<?php echo $shipping_code; ?>');

                    $('#history').before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');

                    $('textarea[name=\'comment\']').val('');

                    $('#order_tracking_number').val('');

                    $('#order-status').html($('select[name=\'order_status_id\'] option:selected').text());
                }

我想这条线应该替换,但它不能正常工作,我应该更改什么?请帮忙!

$('#order-status').html($('select[name=\'order_status_id\'] option:selected').text());

更新: select 框的代码

               <div class="form-group">
                        <label class="col-sm-2 control-label"
                               for="input-order-status"><?php echo $info_data['entry_order_status']; ?></label>
                        <div class="col-sm-10">
                            <select name="order_status_id" id="input-order-status" class="form-control">
                                <?php foreach ($info_data['order_statuses'] as $order_statuses) { ?>
                                    <?php if ($order_statuses['order_status_id'] == $info_data['order_status_id']) { ?>
                                        <option value="<?php echo $order_statuses['order_status_id']; ?>"
                                                selected="selected"><?php echo $order_statuses['name']; ?></option>
                                    <?php } else { ?>
                                        <option
                                            value="<?php echo $order_statuses['order_status_id']; ?>"><?php echo $order_statuses['name']; ?></option>
                                    <?php } ?>
                                <?php } ?>
                            </select>
                        </div>
                    </div>

试试这个:

来自:

$('#order-status').html($('select[name=\'order_status_id\'] option:selected').text());

至:

$('#order-status').html($('#input-order-status option:selected').text());

如果你想用名字调用你的选择框然后改变它

至:

$('#order-status').html($('select[name="order_status_id"] option:selected').text());