gpt4 book ai didi

javascript - Bootstrap下拉菜单点击后消失

转载 作者:行者123 更新时间:2023-12-01 05:27:12 25 4
gpt4 key购买 nike

<div class="container" ng-controller="serviceHistoryController">
<!-- Search box Start -->
<div class="dropdown col-xs-8">
<button class="btn btn-default col-xs-4" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="false" aria-expanded="true">
Select SUT
<span class="caret"></span>
</button>
<ul class="dropdown-menu col-xs-8" aria-labelledby="dropdownMenu1">
<li ng-repeat="sutname in sutlist">
<a href="#" ng-click="sutselected(sutname)">
{{sutname.name}}
</a>
</li>
</ul>
</div>
</div>

上面是我正在使用的 Bootstrap + Angular 下拉代码。但一旦我点击下拉菜单,它就消失了。我正在使用 angular1 + boostrap 3.3.7 和 jquery 1.12.4 库。没有使用其他脚本或 js。

下面是 Angular 函数

app.controller("serviceHistoryController",function($scope){    
let menuitems = [{"sutid":"1","name":"AA"},
{"sutid":"2","name":"BB"},
{"sutid":"3","name":"CC"},
{"sutid":"4","name":"DD"},
{"sutid":"4","name":"EE"}]
$scope.sutlist = menuitems;
$scope.selectedSUT;

$scope.sutselected = function(sutname){
$scope.selectedSUT = sutname;
alert("dropdown sut selected:"+$scope.selectedSUT.name);
}
});

最佳答案

问题出在您的数据类型上使用var查看修改后的 Controller 。

app.controller("serviceHistoryController",function($scope){    
var menuitems = [{"sutid":"1","name":"AA"},
{"sutid":"2","name":"BB"},
{"sutid":"3","name":"CC"},
{"sutid":"4","name":"DD"},
{"sutid":"4","name":"EE"}]
$scope.sutlist = menuitems;
$scope.selectedSUT;

$scope.sutselected = function(sutname){
$scope.selectedSUT = sutname;
alert("dropdown sut selected:"+$scope.selectedSUT.name);
}
});

关于javascript - Bootstrap下拉菜单点击后消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39116314/

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