gpt4 book ai didi

javascript - 如何使用下拉按钮显示范围?

转载 作者:行者123 更新时间:2023-12-03 08:45:16 24 4
gpt4 key购买 nike

我是 Angular 的新手,所以请不要刻薄。我试图根据下拉按钮中单击的选项显示一些文本,但无法使其工作。那么这有什么问题呢?提前致谢。

JSfiddle

HTML

<div ng-app='myApp'>
<div ng-controller="DropdownCtrl">
<div class="btn-group" dropdown is-open="status.isopen">
<button id="single-button" type="button" class="btn btn-default btn-xl" dropdown-toggle ng-disabled="disabled">
Options <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="single-button">
<li role="menuitem"><a href="#/" ng-click="show(first)">Display: First</a></li>
<li role="menuitem"><a href="#/" ng-click="show(second)">Display: Second</a></li>
</ul>
</div>


<div id="separator"></div>

<div class="col-md-12">
{{show.first}}
{{show.second}}
</div>

</div>
</div>

Javascript

var myApp = angular.module('myApp', ['ui.bootstrap']);

myApp.controller('DropdownCtrl', function ($scope) {

$scope.show = function(scope) {
$scope.first = 'First';
$scope.second = 'Second';
};

});

最佳答案

检查这个

Controller

var myApp = angular.module('myApp', ['ui.bootstrap']);
myApp.controller('DropdownCtrl', function ($scope) {
$scope.show = function(value) {
console.log(value);
$scope.data = value;
};
});

HTML:

<div ng-app='myApp'>
<div ng-controller="DropdownCtrl">
<div class="btn-group" dropdown is-open="status.isopen">
<button id="single-button" type="button" class="btn btn-default btn-xl" dropdown-toggle ng-disabled="disabled">
Options <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="single-button">
<li role="menuitem"><a href="#/" ng-click="show('first')">Display: First</a></li>
<li role="menuitem"><a href="#/" ng-click="show('second')">Display: Second</a></li>
</ul>
</div>
<div id="separator"></div>

<div class="col-md-12">
{{data}}
</div>
</div>
</div>

Fiddle

关于javascript - 如何使用下拉按钮显示范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32922592/

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