如何将函数分配给 <span>?在范围中显示数字



如何分配一个函数?在一个跨度中显示一个数字Screуnshot请告诉我该怎么做?用React Js创建

function onlineCount() {
Math.floor(100+480*Math.random()); 
}
setInterval(onlineCount, 1000);
function HeaderTop() {

// const onlineCount = Math.floor(100+480*Math.random()) 
return (
<div className="header-top">
<div className="header-social">
<div className="header-online">
<div className="online-general-bar">
<div className="online-bar"></div>
</div>
<span>{() => onlineCount}</span>

REACT

const root = ReactDOM.createRoot(
document.getElementById('root')
);
function tick() {
const element = (
<span>{Math.floor(100 + 480 * Math.random());
setTimeout(function () { onlineCount(); }, 1000);}
</span>
);
root.render(element);
}
setInterval(tick, 1000);

纯JAVASCRIPT

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function onlineCount() {
document.getElementById("mySpan").innerText = Math.floor(100 + 480 * Math.random());
setTimeout(function () { onlineCount(); }, 1000);
}
setTimeout(function () { onlineCount(); }, 1000);
</script>
</head>
<body>
<form id="form1">
<div>
<span id="mySpan"></span>
</div>
</form>
</body>
</html>

相关内容

  • 没有找到相关文章

最新更新