我正在尝试让我的BS4下拉菜单在下拉切换按钮(即.dropdown-toggle
)中显示用户选择的值
这个问题以前已经被问过了,,但由于它使用了BS3框架,所以有点过时了。它也没有提供一个多次使用dropdown的方法。
我的在这里显示了我目前面临的问题,我是如何调整前面链接的解决方案的。
BS4下拉
<div class="btn-group">
<button class="btn btn-sm dropdown-toggle px-0 mr-3" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Sort by:
</button>
<div class="dropdown-menu">
<a class="dropdown-item active" href="#">Most Recent</a>
<a class="dropdown-item" href="#">Popular</a>
<a class="dropdown-item" href="#">Trending</a>
<a class="dropdown-item" href="#">Acending</a>
<a class="dropdown-item" href="#">Decending</a>
</div>
</div>
我的Jquery尝试
// Find all drop downs and check their classes.
$(".dropdown-menu a").click(function() {
// Find the dropdown toggle and append the text.
$(".dropdown-toggle:first-child").append($(this).text());
});
The question:
如何才能在页面上的所有下拉列表都不受影响的情况下达到预期的效果?此外,当选择一个新值时,我还需要删除附加的文本。
我追求的结果:button value = 'Sort by: Most Recent'
https://stackoverflow.com/questions/56952354
复制相似问题