【发布时间】:2021-09-21 07:09:32
【问题描述】:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {box-sizing: border-box}
body {font-family: "Lato", sans-serif;}
/* Style the tab */
.tab {
float: left;
border: 1px solid #ccc;
background-color: #f1f1f1;
width: 30%;
height: 300px;
}
/* Style the buttons inside the tab */
.tab button {
display: block;
background-color: inherit;
color: black;
padding: 22px 16px;
width: 100%;
border: none;
outline: none;
text-align: left;
cursor: pointer;
transition: 0.3s;
font-size: 17px;
}
/* Change background color of buttons on hover */
.tab button:hover {
background-color: #ddd;
}
/* Create an active/current "tab button" class */
.tab button.active {
background-color: #ccc;
}
/* Style the tab content */
.tabcontent {
float: left;
padding: 0px 12px;
border: 1px solid #ccc;
width: 70%;
border-left: none;
height: 300px;
}
</style>
</head>
<body>
<h2>Vertical Tabs</h2>
<p>This is code i am diplaying included php file which contains process of inserting ,deleting and updating</p>
<p>Currently after data submission or update i have to reload whole page to get current data for three tabs </p>
<p>I need to know how to refresh the selected tab php file to get the current data for selected tab witout reloading page</p>
<p>for example: after i insert data in insert tab after i select update tab it should load and show current data instead of showing old data</p>
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'London')" id="defaultOpen">insert</button>
<button class="tablinks" onclick="openCity(event, 'Paris')">update</button>
<button class="tablinks" onclick="openCity(event, 'Tokyo')">delete</button>
</div>
<div id="London" class="tabcontent">
<h3>insert</h3>
<p>here will be my first php includes</p>
<?php
include "insert.php"; ?>
</div>
<div id="Paris" class="tabcontent">
<h3>update</h3>
<p>here will be my second php includes</p>
<?php
include "update.php"; ?>
</div>
<div id="Tokyo" class="tabcontent">
<h3>delete</h3>
<p>here will be my third php includes</p>
<?php
include "delete.php"; ?>
</div>
<script>
function openCity(evt, cityName) {
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(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();
</script>
</body>
</html>
-
我的代码只是显示我包含在 php 文件中的 php 文件,因此它在标签页加载时已经加载了数据。
-
所以在将数据插入数据库后,它仍然有旧数据用于获取当前数据,我重新加载整个页面以获取新数据。
-
因此,每次完成该过程后,我都必须重新加载整个页面。
##这是我需要的##
- 每次选择选项卡时,我都需要加载包含在 php 中的包含页面
2.如果我只重新加载选定的标签页,那么我将在提交数据后获得新数据
- 然后我将获取当前数据以插入或删除
##描述##
- 在我的代码中,如果您知道我的问题的解决方案可以用任何其他语言(如 jquery)解决,我在代码中使用 javascript 作为选项卡,它也会很有用
【问题讨论】:
-
你需要研究“AJAX”
-
在
ajax做一个简短的调查,你会了解一切,从这里开始教它会很困难。
标签: javascript php html jquery ajax