我有 2 个字符列表。我正在尝试根据数据属性值使用 li 和 html 中的新字符名称更新旧字符列表。单击更改列表时,最终结果如下所示:
//BEFORE
<ul id="new_characters">
<li id="peter"><div data="character1" class="character">Peter Griffin</div></li>
<li id="joe"><div data="character2" class="character">Joe Swanson</div></li>
</ul>
<ul id="old_characters">
<li id="glenn"><span data="character1" class="character">Glenn Quagmire</span></li>
<li id="louis"><span data="character2" class="character">Loius Griffin</span></li>
</ul>
<span id="change">Change List</span>
//AFTER
<ul id="old_characters"> //only this list should change on #change click
<li id="peter"><span data="character1" class="character">Peter Griffin</span></li>
<li id="joe"><span data="character2" class="character">Joe Swanson</span></li>
</ul>
这是一个小提琴:http: //jsfiddle.net/wXnSZ/