javascript - 单击切换时更改徽标的 css 属性
问题描述
当我单击切换时,我想将 css 属性(z-index)更改为导航栏中的徽标。当该切换关闭时,我需要将该属性更改回来。这可能吗?
我的切换有一个类“ubermenu-responsive-toggle-main” 我的徽标有一个类“header-logo” 打开切换有一个类“ubermenu-responsive-toggle-open”
解决方案
<!DOCTYPE html>
<html>
<body>
<div id="demo" customAttribute="value1">this text toogles</div>
<button onclick="myFunction()">Click me</button>
<script>
function myFunction() {
elm=document.getElementById("demo");
elm.setAttribute("customAttribute",elm.getAttribute("customAttribute")=="value1"?"value2":"value1");
}
</script>
<style>
[customAttribute=value2]{
visibility: visible;
}
[customAttribute=value1]{
visibility: hidden;
}
</style>
</body>
</html>
此代码是一个简单的切换,当您单击按钮时将隐藏然后显示文本。关键是 elm.setAttribute("customAttribute",elm.getAttribute("customAttribute")=="value1"?"value2":"value1");
推荐阅读
- sql - 如何使用递归查询将列添加到选择中?
- c# - WiX 静默安装无法启动内置 .EXE:WiX v3
- haskell - Haskell - 在另一种中使用一种数据类型
- javascript - 为什么刷新页面时这段代码有时不运行?
- javascript - 防止在 Google Combochart 视图中过滤某些项目
- php - 从 wp_head 中删除特定样式
- android - 如何在 ListView 上同时实现 onClick 和 onLongClick 监听器?
- vba - 添加对 VBA 代码的动态引用
- amazon-web-services - efs mount 使 arm-linux-gnueabihf-gcc CC 丢失其组件路径
- swift - 安装 Cocoapods 错误