2016-10-08 78 views
0

在以下代码中,当管理员编辑订单时,我在opencart的管理面板中显示order_status。订单状态显示非常好。jQuery:如何用新的元素替换元素,只显示新元素?

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

UPDATE: 代码选择框

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

你迭代这个部分? '<?PHP如果($ info_data [ 'ORDER_STATUS']){?> ​​ ' –

+1

如果您有多个''td id =“order-status”>'那么您不应该使用'ID',您应该使用'class'来代替。 –

+0

no sir这部分没有迭代,它只验证是否启用了order_status, 和我只有一个 – Haroon

回答

2

试试这个:

来自:

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

到:

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

,如果你想与NAME的通话您选择框,然后改变它

到:

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

它工作得很好,谢谢先生! – Haroon

+0

用名称调用selectbox不起作用先生,但通过id调用工程 – Haroon

+0

现在应该工作 –