gpt4 book ai didi

javascript - 我的滑出菜单可以在 HTML 中运行,但不能在 PHP 中运行

转载 作者:行者123 更新时间:2023-11-28 04:30:33 25 4
gpt4 key购买 nike

我有一个简单的滑入和滑出菜单,打开汉堡并关闭 X。在我将它加载到 PHP 和 Wordpress 之前,它运行得很好。当我复制到 WordPress 时,我最初像平常一样将脚本放在我的元标记之前,但这不起作用。我也在其他几个地方尝试过,但没有成功。当我将其插入 PHP 并预览我的网站时,打开和关闭按钮都会显示,但单击时不会出现菜单。我对此很陌生,因此非常感谢任何帮助。谢谢。

我试图在这里制作一个工作示例:https://jsfiddle.net/zq7egqzf/

var button = document.getElementById("button");
var d3 = document.getElementById("d3");
function openNav() {
button.style.display="none";
d3.style.display="block";
}

function closeNav() {
button.style.display="inline-block";
d3.style.display="none";
}
 html {
font-family: "Quicksand", sans-serif;
font-size:12px;
}

/* Header */


header {
border-bottom: 1px solid #E1E0E1;
margin-left: 35px;
margin-right: 35px;
height: 53px;
}

.sidenav {
height: 100%;
width: 200px;
position: absolute;
top: 60px;
left: 0;
z-index: 1;
font-size: 36px;
background-color: #ffffff;
opacity: 0.8;
transition: 0.5s;

}

.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 16px;
color: #000000;
display: block;
transition: 0.3s;
}

.sidenav a:hover, .offcanvas a:focus {
color: #BCBCBC;
}

#d3 {
display: none;
}

.lch {
padding-top: 11px;
padding-left: 13px;
width: 85%;
min-width: 250px;
max-width: 1175px;
position:relative;
}

.lolo {
position: relative;
width: 14%;
min-width: 80px;
max-width:
}

.wrapper {
display: flex;
align-items: content;
vertical-align: middle;
}

h1 {
margin: 0;
}

@media only screen and (max-device-width: 540px) {
h1 {width: 100%;}
}

@media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}

#button {
padding-top: 15px;
}

.homephoto {
margin:30px;
}
    <header>

<div class="wrapper">

<h1 class="menu">

<input id="button" type="image" src="hamburger2.png" onclick="openNav()">

<div id="d3">
<input id="button" type="image" src="close.png" onclick="closeNav()">
<br>
<br>
<br>
<div class="sidenav">
<a href="#"> &nbsp; &nbsp; - p o r t f o l
i o</a> <br>
<a href="#"> &nbsp; &nbsp; - m e e t
&nbsp; l o l o</a><br>
<a href="#"> &nbsp; &nbsp; - i n
s t a </a><br>
<a href="#"> &nbsp; &nbsp; - p r e s s </a>
<br>
<a href="#"> &nbsp; &nbsp; - c i a o</a>
</div>
</div>

</h1>

<h1 class="lch"> <a href="#"> <img
src="lcg2.svg"/> </h1>
<h1 class="lolo"> <a href="#"> ‎<img
src="lolo2.svg"/> </h1>

</div>
</header>

<center>
<div>
<img class="homephoto" src="eclecticmaison.jpg"/>
</div>
</center>



最佳答案

尝试将您的脚本更改为这样

(function(){

var button = document.getElementById("button");
var d3 = document.getElementById("d3");
function openNav() {
button.style.display="none";
d3.style.display="block";
}

function closeNav() {
button.style.display="inline-block";
d3.style.display="none";
}

});

关于javascript - 我的滑出菜单可以在 HTML 中运行,但不能在 PHP 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44644262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com