如何使用jQuery动态更新div.id的innerHTML

时间:2016-08-16 10:18:21

标签: javascript jquery html innerhtml



var obj = {
  "Ethernet": "Up",
  "Ethernet": "Down",
  "USB_Dongle": "Down",
  "USB_Dongle": "Down",
  "X_BROADCOM_COM_PPTPAC": "Down",
  "wanLink": "Up"
}

function renderStatusWanLink(obj) {
  var tmp = jQuery('#WAN_Line').html();
  console.log(tmp);

  if (obj !== false) {
    jQuery('#WAN_Line').html(obj.wanLink);
  }
}

renderStatusWanLink(obj);
renderStatusWanLink(obj);

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<table class="az-table az-table-status table table-condensed table-hover table-striped">
  <tbody>
    <tr>
      <td>WAN Status</td>
      <td>:</td>
      <td id="WAN_Line" width="49%"></td>
    </tr>
  </tbody>
</table>
&#13;
&#13;
&#13;

我想从div #WAN_Line中首先获取html / text内容。最初它将是空的。但是下次它应该在更新时返回一些值。但它总是返回空白。

HTML :(这是在一个表中)

<tr>
    <td>WAN Status</td>
    <td>:</td>
    <td id="WAN_Line" width="49%"></td>
</tr>

使用Javascript:

function renderStatusWanLink(obj)
{
    var tmp = jQuery('#WAN_Line').html();
    console.log(tmp);

    if (obj !== false) {

        jQuery('#WAN_Line').html(obj.wanLink);            
    }
}

obj =

{"Ethernet":"Up",
"Ethernet":"Down",
"USB_Dongle":"Down",
"USB_Dongle":"Down",
"X_BROADCOM_COM_PPTPAC":"Down",
"wanLink":"Up"}

0 个答案:

没有答案