<分区>
标签 javascript html css
<分区>
我正在尝试显示来自 javascript 函数的 nslookup 值,该函数在加载页面时将 nslookup 值返回给 html。
我在 html 页面中有以下脚本:
<html>
<style type="text/css">
.Table
{
display: table;
}
.Title
{
display: table-caption;
text-align: center;
font-weight: bold;
font-size: larger;
}
.Heading
{
display: table-row;
font-weight: bold;
text-align: center;
}
.Row
{
display: table-row;
}
.Cell
{
display: table-cell;
border: solid;
border-width: thin;
padding-left: 20px;
padding-right: 20px;
}
</style>
<body onload="myFunction()">
<h1>"The dns ip is: " <span id="myID"></span></h1>
<div class="Heading">
<div Class="Cell">
<p>G</p>
</div>
<div Class="Cell">
<p>facebook.com</p>
</div>
<div id="test">
<span id="h" class="Cell">
<p>H</p>
</span>
<span id="e" class="cell">
<p>E</p>
</span>
<span id ="Time" class="Cell">
<P> </P>
</span>
</div>
<div Class="Cell">
<p></p>
</div>
</div>
</body>
<button type="button" onclick="myFunction()">Refresh</button>
<script>
function myFunction()
{
//document.body.style.backgroundColor = "red";
document.getElementById("h").style.background="green";
const dns = require('dns');
var status="";
dns.lookup('facebook.com', function(err, result){
var status = result;
});
document.getElementById("Time").innerHTML=status;
}
</script>
</html>
预期: 我希望获得要返回的 url facebook.com 的 dns 值并显示在“The dns ip is:”字段中
实际: 没有任何内容从脚本返回到那里显示
感谢是否有人可以提供帮助?
最佳答案
function myFunction()
{
const dns = require('dns');
dns.lookup('https://facebook.com', function(err, result){
var status = result
document.getElementById("myID").innerHTML=status;
});
}
关于javascript - 无法在 html 页面中显示从 javascript 函数返回的 nslookUp 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57667864/