我们如何为客户站点更改菜单及其选定子菜单的值。?
How Can we change the Value of Menu with its selected submenu, for client site.?
我想更改菜单项及其选定子菜单的值。我首先使用 JS 完成了此操作。但它在加载页面时再次设置为菜单值。
有什么方法可以更改当前会话的菜单值。
如果有人能帮助我,我将不胜感激。
由于您没有粘贴代码来根据您的需要调整代码,我只能向您展示 JavaScript 的 sessionStorage
是如何工作的。 W3schools 有 an example and explanation. If the page is not working you can check this jsfiddle。
sessionStorage 对象等同于localStorage 对象,只是它只存储一个会话的数据。当用户关闭特定浏览器选项卡时,数据将被删除。
<!DOCTYPE html>
<html>
<head>
<script>
function clickCounter() {
if(typeof(Storage) !== "undefined") {
if (sessionStorage.clickcount) {
sessionStorage.clickcount = Number(sessionStorage.clickcount)+1;
} else {
sessionStorage.clickcount = 1;
}
document.getElementById("result").innerHTML = "You have clicked the button " + sessionStorage.clickcount + " time(s) in this session.";
} else {
document.getElementById("result").innerHTML = "Sorry, your browser does not support web storage...";
}
}
</script>
</head>
<body>
<p><button onclick="clickCounter()" type="button">Click me!</button></p>
<div id="result"></div>
<p>Click the button to see the counter increase.</p>
<p>Close the browser tab (or window), and try again, and the counter is reset.</p>
</body>
</html>
谢谢你的回答,现在我找到了答案,是这样的:
<div class="container">
下拉菜单
.dropdown class 用于指示下拉菜单。
使用 .dropdown-menu class 实际构建下拉菜单。
要打开下拉菜单,请使用按钮或带有 class .dropdown-toggle 和 data-toggle="dropdown".[= 的 link 12=]
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown"><?php echo $page[basename($_SERVER['PHP_SELF'])] ?>
<span class="caret"></span></button>
<ul class="dropdown-menu">
<?php
$page=array('index.php'=>'Home','html.php'=>'Html','css.php'=>'CSS','javascript.php'=>'Javascript');
unset($page[basename($_SERVER['PHP_SELF'])]);
foreach ($page as $key => $value) {
?>
<li><a href="<?php echo $key ?>"><?php echo $value ?></a></li>
<?php
}
?>
</ul>
我想更改菜单项及其选定子菜单的值。我首先使用 JS 完成了此操作。但它在加载页面时再次设置为菜单值。
有什么方法可以更改当前会话的菜单值。
如果有人能帮助我,我将不胜感激。
由于您没有粘贴代码来根据您的需要调整代码,我只能向您展示 JavaScript 的 sessionStorage
是如何工作的。 W3schools 有 an example and explanation. If the page is not working you can check this jsfiddle。
sessionStorage 对象等同于localStorage 对象,只是它只存储一个会话的数据。当用户关闭特定浏览器选项卡时,数据将被删除。
<!DOCTYPE html>
<html>
<head>
<script>
function clickCounter() {
if(typeof(Storage) !== "undefined") {
if (sessionStorage.clickcount) {
sessionStorage.clickcount = Number(sessionStorage.clickcount)+1;
} else {
sessionStorage.clickcount = 1;
}
document.getElementById("result").innerHTML = "You have clicked the button " + sessionStorage.clickcount + " time(s) in this session.";
} else {
document.getElementById("result").innerHTML = "Sorry, your browser does not support web storage...";
}
}
</script>
</head>
<body>
<p><button onclick="clickCounter()" type="button">Click me!</button></p>
<div id="result"></div>
<p>Click the button to see the counter increase.</p>
<p>Close the browser tab (or window), and try again, and the counter is reset.</p>
</body>
</html>
谢谢你的回答,现在我找到了答案,是这样的:
<div class="container">
下拉菜单
.dropdown class 用于指示下拉菜单。
使用 .dropdown-menu class 实际构建下拉菜单。
要打开下拉菜单,请使用按钮或带有 class .dropdown-toggle 和 data-toggle="dropdown".[= 的 link 12=]
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown"><?php echo $page[basename($_SERVER['PHP_SELF'])] ?>
<span class="caret"></span></button>
<ul class="dropdown-menu">
<?php
$page=array('index.php'=>'Home','html.php'=>'Html','css.php'=>'CSS','javascript.php'=>'Javascript');
unset($page[basename($_SERVER['PHP_SELF'])]);
foreach ($page as $key => $value) {
?>
<li><a href="<?php echo $key ?>"><?php echo $value ?></a></li>
<?php
}
?>
</ul>