【问题标题】:refreshing or reloading tab content using vertical tab menu使用垂直选项卡菜单刷新或重新加载选项卡内容
【发布时间】: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> 
##这就是我所拥有的##
  1. 我的代码只是显示我包含在 php 文件中的 php 文件,因此它在标签页加载时已经加载了数据。

  2. 所以在将数据插入数据库后,它仍然有旧数据用于获取当前数据,我重新加载整个页面以获取新数据。

  3. 因此,每次完成该过程后,我都必须重新加载整个页面。

##这是我需要的##

  1. 每次选择选项卡时,我都需要加载包含在 php 中的包含页面

2.如果我只重新加载选定的标签页,那么我将在提交数据后获得新数据

  1. 然后我将获取当前数据以插入或删除

##描述##

  1. 在我的代码中,如果您知道我的问题的解决方案可以用任何其他语言(如 jquery)解决,我在代码中使用 javascript 作为选项卡,它也会很有用

【问题讨论】:

标签: javascript php html jquery ajax


【解决方案1】:

您为什么不使用 Jquery load() 而不是 php include() 来满足您的需求,而且非常简单。

例如:-

function somefunction(){
  $('#mydiv').load("phpfile.php");//load a php file into some division
  $('#mydiv').load("phpfile2.php", function(){//Do something after load});
}

你可以用这个做很多事情,比如

  1. 加载某个事件的文件。
  2. 按时间间隔(每 5 秒)加载文件。
  3. 在完成某些任务或进行更改并需要显示时加载文件。

如有任何疑问,请在下方评论。

【讨论】:

  • 感谢我更改为 jquery 加载的提示,但是当我在选项卡之间切换太快时,即使我切换到另一个选项卡,它也会花费太多时间来加载它等待上一个选项卡页面加载然后它开始加载当前页面
  • 如何使用 jquery load 更快地在标签之间切换
  • 没有什么叫加载更快,应该由您自己编写程序,因此如果您尝试在某个部门加载页面,您应该在页面打开后预先加载它。然后在选择标签时,新更新的页面将加载。 span>
猜你喜欢
  • 2014-09-20
  • 1970-01-01
  • 2022-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-10
  • 2012-08-26
相关资源
最近更新 更多