gpt4 book ai didi

html - 单击一个 div 标签并打开另一个页面/html 文件

转载 作者:太空宇宙 更新时间:2023-11-03 22:26:28 25 4
gpt4 key购买 nike

我无法获取 div 标记以在单击时打开另一个页面/本地 html 文件。

我有一个包含 5 个按钮 (div) 的菜单。这些按钮有背景图像而不是颜色,因为 Dream weaver 没有字体。每个按钮还具有悬停功能,可更改 div 以显示倒置图像。

在谷歌搜索如何使整个 div 可点击然后打开下一页(本地文件)之后,没有一种方法对我有用。

例如,我想做的是当单击“productsbutton”div 时,名为“Products.html”的本地 html 文件打开并显示该页面上的内容。

我的源代码是:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link href="CSS/design.css" rel="stylesheet" type="text/css">


<div id="wrapper">

<div id="header"></div>

<div id="menu">

<div id="homebutton"></div>
<div id="Productsbutton"></div>
<div id="Gallerybutton"></div>
<div id="Menubutton"></div>
<div id="Aboutbutton"></div>

</div>

我的 CSS 是

@charset "utf-8";
/* CSS Document */
body{
background-image:url(/Images/background.jpg);
background-repeat: no-repeat;
Width:1400px;
height:1400px;
}

#wrapper{
Width:1000px;
Height:1400px;
margin-left:auto;
margin-right:auto;
padding:5px;
}


#header{
width:1000px;
height:250px;
background-image:url(/Images/banner.png);
}

#menu{
width:1000px;
height:35px;
background-color:#1790e1;
border-radius:5px;
}

#homebutton{
width:200px;
height:35px;
background-image:url(/Images/Menu_Buttons/Home%20Button.png);
float:left;
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
-ms-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
border-bottom-left-radius:5px;
}

#homebutton:hover{
background-image:url(/Images/Menu_Buttons/Home%20Button%20Hover.png);
filter: alpha(opacity=200);
opacity:2;
}

#Aboutbutton{
width:200px;
height:35px;
float:left;
background-image:url(/Images/Menu_Buttons/About.png);
border-bottom-right-radius:5px;
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
-ms-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
}

#Aboutbutton:hover{
background-image:url(/Images/Menu_Buttons/About%20Hover.png);
filter: alpha(opacity=200);
opacity:2;
border-bottom-right-radius:5px;
}

#Gallerybutton{
width:200px;
height:35px;
float:left;
background-image:url(/Images/Menu_Buttons/Gallery.png);
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
-ms-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
}

#Gallerybutton:hover{
background-image:url(/Images/Menu_Buttons/Gallery%20Hover.png);
filter: alpha(opacity=200);
opacity:2;
}

#Menubutton{
width:200px;
height:35px;
float:left;
background-image:url(/Images/Menu_Buttons/Services.png);
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
-ms-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
}

#Menubutton:hover{
background-image:url(/Images/Menu_Buttons/Services%20Hover.png);
filter: alpha(opacity=200);
opacity:2;
}

#Productsbutton{
width:200px;
height:35px;
float:left;
background-image:url(/Images/Menu_Buttons/Products.png);
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
-ms-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
transition: all 0.3s ease;
color:#000000;

}

#Productsbutton:hover{
background-image:url(/Images/Menu_Buttons/Products%20Hover.png);
filter: alpha(opacity=200);
opacity:2;
}

最佳答案

您应该为每个可点击的 div 使用 cursor: pointer; 让用户知道它是可点击的。

然后你甚至应该在每个 div 中调用 onclick() 来触发点击并打开相应的页面。

<div id="homebutton" onclick="openPage('Home.html')"> </div>

在 JS 文件中,

 function openPage(pageUrl){
window.open(pageUrl);
}

有关如何在另一个选项卡上打开页面的模式详细信息,这里是 link to W3Schools

关于html - 单击一个 div 标签并打开另一个页面/html 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50835430/

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