gpt4 book ai didi

JavaScript 在 Firefox 中工作但在 chrome 中不工作

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

Web 控制台没有错误,代码用于隐藏一个元素并显示另一个元素。statsmeasure ID 在 html 中只出现一次。ab ID 也只出现一次。它在 Mozilla Firefox 中运行良好,但在 chrome 中运行不正常。

这是代码。

<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>HeartBeat</title>
<style>
body {
background: #eee;
overflow-x: hidden;
margin: 0px;
}
.conta{
max-width: 750px;
margin-left: auto;
margin-right: auto;

}
.head {

background: #FF6969;
color: #fff;
font-size: 1.5em;
padding: 20px;
text-align: center;

}
.bd {
background: #fff;
padding: 10px;
}
.active {
border-bottom: 3px solid #FD0000;
}
#stats {
display: none;
background: #fff;
}
a {
text-decoration: none;
color: #423C3C;
font-weight: bold;
font-size: 1.4em;
}
a:hover {
border-bottom: 3px solid #FD0000;

}
h1 {
color:#667184;
}
h2 {
color:#D0D4DB;
}
.two-col {
display:block;
max-width: 50%;
min-width: 49%;
float: left;
text-align: center;
}
.three-col {
display:inline-block;
max-width: 33%;
min-width: 32%;
float: center;
text-align: center;
}
.text-center {
text-align: center;
}
.row {
max-width:100%;
}
.white-back {
background: #fff;
}

</style>
</head>
<body>
<div class="conta">
<div class="head">
<img src="h-1.png" width="50px" style="float:left; margin: -10px;"> Heart<b>Beat</b>
</div>
<div class="bd">

<div class="two-col"><a id="a" class="active" onClick='aTab()' href="#">Measure</a></div>
<div class="two-col"><a id="b" onClick='bTab()' href="#">Statistics</a></div>
<br/> <br/>

<div id="measure" class="text-center">
<img src="heart.jpg" width="90%">
<h1><span class="light">0</span>72</h1>
<h2>Beats Per Second</h2>
<img src="wave.png" alt="" width="90%" >
</div>
<div id="stats" class="text-center"> <br/>
<div class="row">
<div class="three-col"><a href="#">Day</a></div>
<div class="three-col"><a href="#">Month</a></div>
<div class="three-col"><a href="#">Year</a></div>
</div><div class="row"><br/> <br/>
<img src="cntr_img.jpg" alt="" width="80%"><br/>
<div class="three-col"><h2>Max</h2><h2>50</h2></div>
<div class="three-col"><h2>Min</h2><h2>157</h2></div>
<div class="three-col"><h2>Avg</h2><h2>81</h2></div>
</div>
</div>

</div>
</div>
<script type="text/javascript">
function aTab() {
document.getElementById("stats").style="display: none;";
document.getElementById("measure").style="display: block;";
document.getElementById("b").className="";
document.getElementById("a").className="active";
}
function bTab() {
document.getElementById("stats").style="display: block;";
document.getElementById("measure").style="display: none;";
document.getElementById("b").className="active";
document.getElementById("a").className="";
}
</script>
</body>
</html>

我。编辑了代码。

最佳答案

您不应使用 style = "somestring",而应使用 style.someProperty = someValue

Here是一个在 chrome 中显示工作代码的 fiddle 。

这是代码(只更改了 JS):

function aTab() {
document.getElementById("stats").style.display = "none";
document.getElementById("measure").style.display = "block";
document.getElementById("b").className="";
document.getElementById("a").className="active";
}
function bTab() {
document.getElementById("stats").style.display = "block";
document.getElementById("measure").style.display = "none";
document.getElementById("b").className="active";
document.getElementById("a").className="";
}

但是,我可能会稍微重写您当前的 JavaScript 以使其更高效一些。 Here这就是我通常会写这样的东西的方式。代码在这里:

function GID(id) {
return document.getElementById(id);
}

var statsTab = GID("stats");
var measureTab = GID("measure");
var a = GID("a");
var b = GID("b");

function aTab() {
statsTab.style.display = "none";
measureTab.style.display = "block";
a.className = "active";
b.className = "";
}

function bTab() {
statsTab.style.display = "block";
measureTab.style.display = "none";
a.className = "";
b.className = "active";
}

关于JavaScript 在 Firefox 中工作但在 chrome 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34565672/

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