gpt4 book ai didi

javascript - 如何使用 jQuery 获取 div.id 的innerHTML(动态更新)

转载 作者:行者123 更新时间:2023-11-27 22:37:47 25 4
gpt4 key购买 nike

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>

我试图首先从 div #WAN_Line 内部获取 html/文本内容。最初它是空的。但下次它应该在更新时返回一些值。但它总是返回空。

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

对象=

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

最佳答案

如果一切顺利,它应该可以工作。使用您给定的对象和代码,下面的代码非常适合我。在下面的代码 spinet 中单击按钮更改 td html

<html>
<head>
<script src="js/jquery-1.7.1.min.js"></script>


<script type="text/javascript">

var obj={"Ethernet":"Up",
"Ethernet":"Down",
"USB_Dongle":"Down",
"USB_Dongle":"Down",
"X_BROADCOM_COM_PPTPAC":"Down",
"wanLink":"Up"};
function removeLine() {

var tmp = jQuery('#WAN_Line').html();
console.log(tmp);

$('#WAN_Line').html("updated code");
}


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

if (obj !== false) {

jQuery('#WAN_Line').html(obj.wanLink);
}
}
</script>



</head>
<body>
<div >

<table>

<tr>
<td>WAN Status</td>

<td id="WAN_Line" width="49%"></td>
</tr>
</table>
</div>
<button onclick="renderStatusWanLink()">click to change text</button>

</body>
</html>

关于javascript - 如何使用 jQuery 获取 div.id 的innerHTML(动态更新),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38972291/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com