gpt4 book ai didi

twitter-bootstrap - 带有下拉菜单的 Bootstrap-4 按钮选择的值不显示

转载 作者:行者123 更新时间:2023-12-03 23:39:30 26 4
gpt4 key购买 nike

我使用的是 bootstrap-4 带下拉菜单的按钮 我有一些问题选择的值不显示此下拉菜单?我想知道正确选择值时如何设置货币名称,我的代码有问题,为此获取一次所有值,您可以理解该问题,请查看snippet

$(".dropdown-menu ").click(function(){

$(this).parents(".input-group-btn").find('.btn').text($(this).text());


});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
<div class="row">
<div class="col-lg-6">
<div class="input-group">
<div class="input-group-btn">
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Currency
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">USD</a>
<a class="dropdown-item" href="#">AUS</a>

</div>
</div>
<input type="text" class="form-control" aria-label="Text input with dropdown button">
</div>
</div>

</div>

最佳答案

我解决了我的问题解决方案01
按钮像选择框一样工作,我更改了我的 script

<script>

$('.dropdown-menu a').on('click', function(){
$('.dropdown-toggle').html($(this).html());
})
</script>

现在它为我工作

	$('.dropdown-menu a').on('click', function(){    
$('.dropdown-toggle').html($(this).html());
})
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
<div class="row">
<div class="col-lg-6">
<div class="input-group">
<div class="input-group-btn">
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Currency
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">USD</a>
<a class="dropdown-item" href="#">AUS</a>

</div>
</div>
<input type="text" class="form-control" aria-label="Text input with dropdown button">
</div>
</div>

</div>

解决方案-02脚本

        $(".dropdown-menu a ").click(function(){

$(this).parents(".input-group-btn").find('.btn').text($(this).text());


});

$(".dropdown-menu a ").click(function(){

$(this).parents(".input-group-btn").find('.btn').text($(this).text());


});
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
<div class="row">
<div class="col-lg-6">
<div class="input-group">
<div class="input-group-btn">
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Currency
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">USD</a>
<a class="dropdown-item" href="#">AUS</a>

</div>
</div>
<input type="text" class="form-control" aria-label="Text input with dropdown button">
</div>
</div>

</div>

关于twitter-bootstrap - 带有下拉菜单的 Bootstrap-4 按钮选择的值不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47828448/

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