這應該很簡單。基本上,當單擊列表中的項目時,將文本插入/替換到目標div中。 'replaceWith'可能不是要使用的東西,因爲它會刪除原始數據。 另外,如何將「selected」類添加到目標div中的文本。更改文本div onClick列表中的項目
反正這裏是我到目前爲止有:http://jsfiddle.net/BM8Cb/
HTML
<div class="selected" id="here">
<li>All</li>
</div>
<hr>
<ul>
<li>All</li>
<li>Category 1</li>
<li>Category 2</li>
<li>Category 3</li>
</ul>
CSS
ul {list-style:none;padding:0; margin:0;}
li {cursor:pointer;}
li:hover {color:red;}
.selected {color:red;}
JS
$("li").click(function() {
$("#here").replaceWith(this);
});
感謝您的幫助
嘗試[HTML()](http://api.jquery.com/html/)和[addClass()](HTTP:// API。 jquery.com/addClass/)。 –
LI元素不能是DIV的子元素嗎? – adeneo
http://jsfiddle.net/BM8Cb/2/ – adeneo