點擊我的側欄菜單中的其中一個鏈接時,如何動態替換現有的div
內容與其對應的div
並將其重新加載到#content
DIV?我是jQuery友好的。下面是HTML標記:交換和更改div內容並替換其他div內容
#container {
bottom: 0;
left: 0;
top: 0;
right: 0;
margin: auto;
position: absolute;
width: 900px;
height: 600px;
}
#list {
list-style-type: none;
padding: 0;
margin: 0;
}
#list li {
margin:0 0 10px 0;
background: grey;
padding: 3px;
cursor: pointer;
}
.item {
width: 100%;
height: 100%;
background: rgb(192,192,192);
}
#menu {
float: left;
width: 25%;
background-color: #ff99CC;
height: 100%;
}
#content {
float: left;
width: 75%;
background-color: rgb(192,192,192);
height: 100%;
}
<div id="container">
<div id="menu">
<ul id="list">
<li>Coffee</li>
<li>Tea</li>
<li>Ice Cream</li>
</ul>
</div>
<div id="content">
<div id="item1">Things about coffee...</div>
<div id="item2">Things about tea...</div>
<div id="item3">Things about ice cream...</div>
</div>
</div>
所以基本上你什麼都沒有? – adeneo
您忘記了在問題中輸入JavaScript代碼。 div內容從哪裏加載? –
內容正在從ID的item1/item2/item3的div加載,即。如果用戶點擊「咖啡」,則要加載的動態內容爲ID爲#item1 – BobbyJones