使用JS显示与班级的显示Divs



我想通过API拉动显示将这些项目显示为下拉列表而不是Divs。

<div class="student"><a href="#">Joe Dullah</a></div>
<div class="student"><a href="#">Sarah Jenkins</a></div>
<div class="student"><a href="#">Cay Holton</a></div>
<div class="student"><a href="#">Alex Poe</a></div>

任何帮助都非常感谢

您可以在dinam上附加一个 select元素,并附加每个 a元素,请参见以下内容:

$(function() {
    var $select = $('<select />');
    $(this).find('a').each(function() {
        var $option = $('<option />');
        $option.attr('value', $(this).attr('href')).html($(this).html());
        $select.append($option);
    });
    $("#list").replaceWith($select);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="list">
  <div class="student"><a href="#">Joe Dullah</a></div>
  <div class="student"><a href="#">Sarah Jenkins</a></div>
  <div class="student"><a href="#">Cay Holton</a></div>
  <div class="student"><a href="#">Alex Poe</a></div>
</div>

我希望它能帮助您,再见。

最新更新