gpt4 book ai didi

Javascript 动态页面

转载 作者:行者123 更新时间:2023-11-28 04:37:02 24 4
gpt4 key购买 nike

小背景:该站点用于大学作业,我们不允许使用 3rd 方库,例如 bootstrap 等。我以为我有一个解决方案,但我只能让它为 2 个按钮工作(显示或隐藏相反的一个)但不是多个。我将至少有 10 个按钮。

我曾尝试研究堆栈溢出但找不到解决方案。这是我的 HTML+CSS。主页是默认页面,单击按钮时,其余页面应在下方的空白区域可见。这是一个产品页面。

JSFIDDLE:https://jsfiddle.net/33n7yb5h/

任何帮助将不胜感激,它不需要是一个书面解决方案,但只需将我指向正确的方向就可以了......我几乎没有 javascript 知识所以我不完全确定我应该是什么首先谷歌搜索...

<html>
<head>
<title>Design</title>
<link rel="stylesheet" type="text/css" href="css/store.css">
<script type="text/javascript" src="javascript/js.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
</head>

<body>
<ul>
<li id="left"><a href="#home">Company</a></li>
<li id="left"><a href="#home">Sales</a></li>
<li id="left"><a href="#home">About</a></li>
<li id="left"><a href="#home">Contact</a></li>
<li id="right1"><a href="">Cart</a></li>
<li id="right2" onclick="myFunction()"><a href="">Geolocate</a></li>
</ul>

<dialog id="myDialog">Your IP address: <?php echo $_SERVER['REMOTE_ADDR']; ?></dialog>

<div id="items">
<ul>
<li id="left"><a href="">Home</a></li>
<li id="Cars"><a href="">Super Cars</a></li>
<li id="Cars"><a href="">Topic 2</a></li>
</ul>

<div id="homepage">
<span><p> Welcome to the store</p></span>
</div>

<div id="showCars">
<div class="productBox">
<div class="productPicture">
</div>
</div>
</div>
</div>

</body>
</html>

ul{list-style-type: none; margin: 0; padding: 0; overflow: hidden; background-color: #363377; border-bottom: 1px solid white;}
li a{display: inline-block; color: white; text-align: center; padding: 14px 16px; text-decoration: none;}
#left, #Cars{float: left; border-right:solid 1px #fff;}
#right1, #right2{float: right;}
#left:hover, #right:hover, #Cars:hover{background-color: #555;}

body{
margin: 0px;
padding: 0px;
font-family: tahoma;
background-image: "/img/bg.jpg";
}

p{
text-align: center;
}

#items{
display: inline-block;
border: 1px solid black;
padding: 10px;
margin-top: 25px;
margin-left: 225px;
margin-right: 225px;
position: absolute;
width: 80%;
height: 80%;
-moz-box-shadow: 1px 2px 4px rgba(0, 0, 0,0.5);
-webkit-box-shadow: 1px 2px 4px rgba(0, 0, 0, .5);
box-shadow: 1px 2px 4px rgba(0, 0, 0, .5);
background: white;
overflow: hidden;
}

.productBox{
border: 2px solid black;
width: 200px;
height: 300px;
margin-top: 5px;
text-align: center;
}

.productPicture{
border: 1px solid black;
width: 90%;
height: 150px;
margin: 0 auto;
margin-top: 5px;
padding: 5px;
display: inline-block;
}

#showCars{
display: none;
}

最佳答案

如果我正确理解您的需要,这里有一些伪代码:有很多方法可以做到这一点,我没有太多要继续的,所以这里只是 1 个例子。

<div>
<button onclick="cars()" value="show cars"></button> <!-- if they click this button call the function cars() -->
<button onclick="boats()" value="show boats"></button>
<ul>
<li id=IDname0></li>
<li id=IDname1></li>
<li id=IDname2></li>
</ul>


</div>




<script>

var cars = ["Saab", "Volvo", "BMW"]; //create an array of values you want to load into your tags
var boats = ["Fishing", "Raft", "Other"];

var x = 0;

Function cars()
{
// for each element in cars,
for ( x=0; x<cars.length; x++ )
{
//acquire the elemt by the ID name, and REPLACE the inner HTML with the value at array cars element x. if you want to add to the inner HTML, use += instead of just =
Document.getElementById('IDname'+x).innerHtml = cars[x]; // will acquire 'IDname0' , 'IDname1', etc.. each tag with an ID of that name ( from your <li> above
}
}

Function boats()
{
for ( x=0; x<cars.length; x++ )
{
Document.getElementById('IDname'+x).innerHtml = boats[x];
}
}



</script>

关于Javascript 动态页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41419697/

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