gpt4 book ai didi

javascript - 单击列表中项目时更改 div 中的文本

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

这应该很简单。基本上,当单击列表中的项目时,文本将被插入/替换到目标 div 中。 “replaceWith”可能不适合使用,因为它会删除原始数据。另外,如何将“selected”类添加到目标 div 中的文本中。

无论如何,这是我到目前为止所拥有的: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);

});

感谢您的帮助

最佳答案

怎么样

$("li.item").click(function() {
$("#here").html($(this).html());
});

如果您需要的只是文本。

关于javascript - 单击列表中项目时更改 div 中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17934520/

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