HTML:如何在html中每次点击标签时刷新page/document?
HTML: How to refresh page/document while clicking tabs in each time in html?
我准备了一个带有标签的 html 页面。每个选项卡都有输入字段。下面是 html 代码。
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {font-family: Arial;}
/* Style the tab */
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
/* Style the buttons inside the tab */
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
font-size: 17px;
}
/* Change background color of buttons on hover */
.tab button:hover {
background-color: #ddd;
}
/* Create an active/current tablink class */
.tab button.active {
background-color: #ccc;
}
/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}
</style>
</head>
<body>
<div class="tab">
<button class="tablinks" onclick="openTab(event, 'One')" id="defaultOpen">One</button>
<button class="tablinks" onclick="openTab(event, 'Two')">Two</button>
<button class="tablinks" onclick="openTab(event, 'Three')">Three</button>
</div>
<div id="One" class="tabcontent">
<h3>One</h3>
One :
<input type="number" min="0.0" id="txtOne" autofocus="autofocus" />
</div>
<div id="Two" class="tabcontent">
<h3>Two</h3>
Two :
<input type="number" min="0.0" id="txtTwo" autofocus="autofocus" />
</div>
<div id="Three" class="tabcontent">
<h3>Three</h3>
Three :
<input type="number" min="0.0" id="txtThree" autofocus="autofocus" />
</div>
<script>
function openTab(evt, Name) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(Name).style.display = "block";
evt.currentTarget.className += " active";
document.getElementById("txtOne").focus();
document.getElementById("txtTwo").focus();
document.getElementById("txtThree").focus();
}
// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();
</script>
</body>
</html>
我第一次单击每个选项卡并在输入字段中输入了一些值。第二次单击每个选项卡时,输入字段已输入 values.Now 我想清除输入字段或 reload/refresh 页面,同时进一步单击选项卡并希望设置自动聚焦输入字段.指导我的情况。提前致谢。
尝试重置值
function reset(Name) {
document.getElementById("txt"+Name).value = '';
}
function openTab(evt, Name) {
reset(Name);
// your code
}
我准备了一个带有标签的 html 页面。每个选项卡都有输入字段。下面是 html 代码。
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {font-family: Arial;}
/* Style the tab */
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
/* Style the buttons inside the tab */
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
font-size: 17px;
}
/* Change background color of buttons on hover */
.tab button:hover {
background-color: #ddd;
}
/* Create an active/current tablink class */
.tab button.active {
background-color: #ccc;
}
/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}
</style>
</head>
<body>
<div class="tab">
<button class="tablinks" onclick="openTab(event, 'One')" id="defaultOpen">One</button>
<button class="tablinks" onclick="openTab(event, 'Two')">Two</button>
<button class="tablinks" onclick="openTab(event, 'Three')">Three</button>
</div>
<div id="One" class="tabcontent">
<h3>One</h3>
One :
<input type="number" min="0.0" id="txtOne" autofocus="autofocus" />
</div>
<div id="Two" class="tabcontent">
<h3>Two</h3>
Two :
<input type="number" min="0.0" id="txtTwo" autofocus="autofocus" />
</div>
<div id="Three" class="tabcontent">
<h3>Three</h3>
Three :
<input type="number" min="0.0" id="txtThree" autofocus="autofocus" />
</div>
<script>
function openTab(evt, Name) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(Name).style.display = "block";
evt.currentTarget.className += " active";
document.getElementById("txtOne").focus();
document.getElementById("txtTwo").focus();
document.getElementById("txtThree").focus();
}
// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();
</script>
</body>
</html>
我第一次单击每个选项卡并在输入字段中输入了一些值。第二次单击每个选项卡时,输入字段已输入 values.Now 我想清除输入字段或 reload/refresh 页面,同时进一步单击选项卡并希望设置自动聚焦输入字段.指导我的情况。提前致谢。
尝试重置值
function reset(Name) {
document.getElementById("txt"+Name).value = '';
}
function openTab(evt, Name) {
reset(Name);
// your code
}