gpt4 book ai didi

javascript - 如何使更改其标题的下拉按钮具有不同的链接?

转载 作者:搜寻专家 更新时间:2023-11-01 04:36:01 25 4
gpt4 key购买 nike

到目前为止,我已经设法让 bootstrap 下拉按钮根据单击的项目更改其标题。

enter image description here

Codepen

但除此之外,我希望每个下拉项在单击时都有自己的链接。

我该怎么做?

HTML

<div ng-app='myApp'>
<div ng-controller='DropdownCtrl'>

<div class="btn-group" uib-dropdown is-open="status.isopen">
<button id="single-button" type="button" class="btn btn-primary" uib-dropdown-toggle ng-disabled="disabled">
{{button}} <span class="caret"></span>
</button>
<ul class="uib-dropdown-menu" role="menu" aria-labelledby="single-button">
<li role="menuitem">
<a href="#" ng-click="change(action)" ng-repeat="action in actions">{{action}}</a>
</li>
</ul>
</div>

</div>
</div>

CSS

angular.module('myApp', ['ui.bootstrap']).controller('DropdownCtrl', function($scope) {
$scope.button = "Button dropdown";
$scope.actions = [
"Action", "Another Action", "Something else here"
];

$scope.change = function(name){
$scope.button = name;
}
});

最佳答案

做这样的事情,使用 ng-href

先把按钮改成anchor,加上ng-href属性;

<a href ng-href="{{ href }}" id="single-button" class="btn btn-primary" uib-dropdown-toggle ng-disabled="disabled">
{{ name }} <span class="caret"></span>
</a>

然后改变 actions 变量来保存一个对象数组:

$scope.actions = [
{
name: 'Action',
href: 'action.html'
},
{
name: 'Another Action',
href: 'another_action.html'
},
{
name: 'Something else here',
href: 'something_else_here.html'
}
];

最后修改更改函数以更新操作的名称​​和 href

$scope.change = function(action){
$scope.name = action.name;
$scope.href = action.href;
}

编辑 现在有一个 CodePen example .请注意,我已将按钮更改为拆分按钮(否则 href 根本没有用,因为它会被切换覆盖)。

关于javascript - 如何使更改其标题的下拉按钮具有不同的链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33298195/

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