当我点击同一页面上的元素时如何加载不同的文字?

时间:2018-02-20 13:26:23

标签: javascript php angularjs

我目前正在尝试构建一个网站,该网站可以在同一页面中执行我想要的所有功能,而不是在不同的页面中导航。我的页面目前看起来像

enter image description here

我希望当我从侧边栏单击客户端以在我的侧边栏右侧的欢迎用户消息的位置加载表单时。所有客户的形式都是一样的。是否也可以保存我将在变量中选择的客户端,以便以后可以使用它从mysql数据库接收元素?

任何人都可以请求我吗? 我的源代码如下:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body {
    font-family: "Lato", sans-serif;
}

/* Fixed sidenav, full height */
.sidenav {
    height: 100%;
    width: 200px;
    position: fixed;
    z-index: 1;
    top: 0;
    left: 0;
    background-color: #111;
    overflow-x: hidden;
    padding-top: 20px;
}

/* Style the sidenav links and the dropdown button */
.sidenav a, .dropdown-btn {
    padding: 6px 8px 6px 16px;
    text-decoration: none;
    font-size: 20px;
    color: #818181;
    display: block;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    outline: none;
}

/* On mouse-over */
.sidenav a:hover, .dropdown-btn:hover {
    color: #f1f1f1;
}

/* Main content */
.main {
    margin-left: 200px; /* Same as the width of the sidenav */
    font-size: 20px; /* Increased text to enable scrolling */
    padding: 0px 10px;
}

/* Add an active class to the active dropdown button */
.active {
    background-color: green;
    color: white;
}

/* Dropdown container (hidden by default). Optional: add a lighter background color and some left padding to change the design of the dropdown content */
.dropdown-container {
    display: none;
    background-color: #262626;
    padding-left: 8px;
}

/* Optional: Style the caret down icon */
.fa-caret-down {
    float: right;
    padding-right: 8px;
}

/* Some media queries for responsiveness */
@media screen and (max-height: 450px) {
    .sidenav {padding-top: 15px;}
    .sidenav a {font-size: 18px;}
}
</style>
</head>
<body>

<div class="sidenav">
  <button class="dropdown-btn">Clients 
    <i class="fa fa-caret-down"></i>
  </button>
  <div class="dropdown-container">
    <a href="#">Client 1</a>
    <a href="#">Client 2</a>
    <a href="#">Client 3</a>
  </div>
</div>

<div class="main">
  <h2>Welcome user</h2>
  <p>Click on the dropdown button to open the dropdown menu inside the side navigation.</p>
  <p>This sidebar is of full height (100%) and always shown.</p>
  <p>Some random text..</p>
</div>

<script>
/* Loop through all dropdown buttons to toggle between hiding and showing its dropdown content - This allows the user to have multiple dropdowns without any conflict */
var dropdown = document.getElementsByClassName("dropdown-btn");
var i;

for (i = 0; i < dropdown.length; i++) {
  dropdown[i].addEventListener("click", function() {
    this.classList.toggle("active");
    var dropdownContent = this.nextElementSibling;
    if (dropdownContent.style.display === "block") {
      dropdownContent.style.display = "none";
    } else {
      dropdownContent.style.display = "block";
    }
  });
}
</script>

</body>
</html> 

表示感谢

1 个答案:

答案 0 :(得分:1)

根据我的理解,您正在尝试开发SPA(单页应用程序)。

我建议你使用像AngularJS或ReactJS&amp; amp;使用路由功能来实现这一点。

但如果你是JS的初学者。

您可以使用Jquery's @app.callback( Output(component_id='graphics_div', component_property='children'), [Input(component_id='button_id', component_property='n_clicks')] ) def callback_function(n_clicks): print(n_clicks) if n_clicks is None: return "" name = "graph_" + str(n_clicks) content.graph_names.append(name) return content.graphics_layout &amp; app.layout = html.Div([ html.Div(id='content'), dcc.Location(id='location', refresh=False), html.Div(dt.DataTable(rows=[{}]), style={‘display’: ‘none’}) ]) 函数:

请参阅此链接:

Replace Div Content onclick