gpt4 book ai didi

javascript - Angularjs ng-重复 : how to target an element

转载 作者:太空宇宙 更新时间:2023-11-04 14:05:52 25 4
gpt4 key购买 nike

我有一个 div 元素列表,当客户选择一个元素时,会出现详细 View 。后面,我想将我的列表定位到所选元素。

<div id="patient{{patient.PId}}" class="div-patient" ng-repeat="patient in patients">
<p>{{patient.name}}</p>
</div>

我已经测试了很多代码来滚动选定的患者:

$(window).scrollTop($("#patient"+$rootScope.selectedPatient).offset().top);
// or
$("html, body").animate({ scrollTop:angular.element("#patient"+$rootScope.selectedPatient).prop( 'offsetTop' ) });
//or
$(window).scrollTop(angular.element("#patient"+$rootScope.selectedPatient).prop( 'offsetTop' ));

CSS div-patient:

position: absolute;
height: 330px;
margin-bottom: 30px;
top: {{360*fixTopCell($index)}}px;

但是

$("#patient"+$rootScope.selectedPatient).offset().top

angular.element("#patient"+$rootScope.selectedPatient).prop( 'offsetTop' )

一直返回0。

当我使用 table 标签而不是 div 时它起作用。

我看到函数 scrollTop 在 Android 4.X 中不可用。是否有其他解决方案可以针对返回列表后选择的元素?

最佳答案

It works when i use a table tag INSTEAD of a div.

确保您的 ID 未被使用 #patient。也许你尝试调用一个已经使用过的 id!

关于javascript - Angularjs ng-重复 : how to target an element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21117577/

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