jQuery:如何用新元素替换一个元素,并且只显示新元素


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

在下面的代码中,当管理员编辑订单时,我在openart的管理面板中显示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 } ?>

但是当管理员通过从下拉列表中选择更新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());

更新:选择框的代码

               <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());

如果你想用name来调用你的selectbox,那就把它改成

:

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