gpt4 book ai didi

javascript - 单击 div 更改 url 位置

转载 作者:行者123 更新时间:2023-11-28 19:43:17 24 4
gpt4 key购买 nike

我想在单击 div 时更改位置。

下面是代码

    <div class="divsub" ng-repeat="item1 in content" ng-click="go('/{{item1.title }}')">
<div class="divsubtitle"><a >{{item1.title}}</a></div>
<div class="divsubinner"></div>
<div class="divsublink">
<div style="float:left;text-decoration:underline;margin-left:19px">View Demo</div>
<div style="float:left;text-decoration:underline;margin-left:10px">Download</div>
</div>
</div>

下面是我的 Controller

first2.controller('nameListCtrl', function ($scope,urls_list) 
{
$scope.content=urls_list;
$scope.go=function(path)
{
alert(path)
}
});

为什么警报在点击 div 时不起作用

最佳答案

无需使用插值{{ }},因为它已经是 Angular Directive(指令)内的 Angular 表达式ng-click

只需使用

ng-click="go(item1.title)"

另请参阅何时在 Angular Directive(指令)中使用单括号、双括号和不使用大括号: https://stackoverflow.com/a/17879046/1177295

关于javascript - 单击 div 更改 url 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24696238/

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