简体   繁体   English

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

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

In the following code I am showing order_status in admin panel of opencart when admin edits an order. 在以下代码中,当管理员编辑订单时,我在opencart的管理面板中显示order_status。 The order status is showing perfectly fine. 订单状态显示良好。

            <?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 } ?>

But when admin update the order_status by selecting from a drop down list it shows the updated order_status with the old order_status. 但是,当管理员通过从下拉列表中进行选择来更新order_status时,它将显示带有旧order_status的更新后的order_status。 I need to only show the updated order_status , How can I replace the old status with the updated 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());
                }

I guess this line should do the replacement , but it is not working properly , what should I change? 我猜这行应该进行替换,但是它不能正常工作,我应该改变什么? Please Help ! 请帮忙 !

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

UPDATE : Code for select box 更新:选择框的代码

               <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>

Try this: 尝试这个:

from: 从:

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

to: 至:

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

if you want to call your selectbox with name then change it 如果您想使用名称调用选择框,请进行更改

to: 至:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM