gpt4 book ai didi

Javascript ng-href 在 ng-repeat 中不起作用

转载 作者:行者123 更新时间:2023-11-28 05:39:34 24 4
gpt4 key购买 nike

我有一个 Accordion ,当我点击它时它正在打开。当我不使用 ng-repeat 时一切正常,但是一旦我使用它,它就不会转到我的 href 地址,而是转到/home。这是我的 HTML 代码:

   <div class="accordion" ng-repeat="department in allDepartments">
<div class="accordion-section">
<a class="accordion-section-title" ng-href="#{{department.name}}" >{{department.name}} </a>

<div ng-attr-id="{{department.name}}" class="accordion-section-content" target="_self">
<p>Mauris interdum fringilla augue vitae tincidunt. Curabitur vitae tortor id eros euismod ultrices. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent nulla mi, rutrum ut feugiat at, vestibulum ut neque? Cras tincidunt enim vel aliquet facilisis. Duis congue ullamcorper vehicula. Proin nunc lacus, semper sit amet elit sit amet, aliquet pulvinar erat. Nunc pretium quis sapien eu rhoncus. Suspendisse ornare gravida mi, et placerat tellus tempor vitae.</p>
</div><!--end .accordion-section-content-->
</div><!--end .accordion-section-->
</div><!--end .accordion-->

这是我的 JS 代码:

$(document).ready(function() {
function close_accordion_section() {
$('.accordion .accordion-section-title').removeClass('active');
$('.accordion .accordion-section-content').slideUp(300).removeClass('open');
}

$('.accordion-section-title').click(function(e) {
// Grab current anchor value
var currentAttrValue = $(this).attr('href');

if($(e.target).is('.active')) {
close_accordion_section();
}else {
close_accordion_section();

// Add active class to section title
$(this).addClass('active');
// Open up the hidden content panel
$('.accordion ' + currentAttrValue).slideDown(300).addClass('open');
}

e.preventDefault();
});
});

最后是我的 CSS 代码:

/*----- Accordion -----*/
.accordion, .accordion * {
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
}

.accordion {
overflow:hidden;
box-shadow:0px 1px 3px rgba(0,0,0,0.25);
border-radius:3px;
background:#f7f7f7;
}

/*----- Section Titles -----*/
.accordion-section-title {
width:100%;
padding:15px;
display:inline-block;
border-bottom:1px solid #1a1a1a;
background:#333;
transition:all linear 0.15s;
/* Type */
font-size:1.200em;
text-shadow:0px 1px 0px #1a1a1a;
color:#fff;
}

.accordion-section-title.active, .accordion-section-title:hover {
background:#4c4c4c;
/* Type */
text-decoration:none;
}

.accordion-section:last-child .accordion-section-title {
border-bottom:none;
}

/*----- Section Content -----*/
.accordion-section-content {
padding:15px;
display:none;
}

最佳答案

您正在混合使用 jQuery 和 AngularJs(糟糕的做法)...但是在 AngularJs 中,散列字符 ('#') 用于更改 View (yoursite/#/view1),而在纯 html 中,它用于转发页面有 id (yoursite/#id) 的地方

这就是您的浏览器在您的主页上重定向您的原因

关于Javascript ng-href 在 ng-repeat 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37988111/

24 4 0
文章推荐: c++ - 在 Halide 管道中访问函数
文章推荐: ios - 我正在尝试使用 Swift Codable 从 subreddit 解析 JSON。为什么我的对象返回零?
文章推荐: php - 当 jquery 用于自动刷新时创建的附加
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com