我創建了一個表,其中包含從ajax調用中獲取的值,並且每個表都具有帶data-id屬性的錨點標記。jQuery - 錨點標記的onClick移動到動態創建div li元素並突出顯示
此外,我創建了一個時間軸視圖(默認情況下隱藏)動態具有相同的值,並有一個滾動視圖 - 因爲有1000個事件。
當用戶點擊錨標籤時,我該如何移動到時間線中的特定li元素並隱藏表格。
function create_table(data) {
var tr = $('<tr>');
$.each(data, function(idx, ele) {
tr.append("<<td><p><a class='details' data-id='" + data['id'] + "href=" + data['link'] + "> Link </a></p></td>")
}
$('tbody').append(tr);
}
function create_time(data) {
var ul = $("<ul>");
$.each(data, function(idx, ele) {
ul.append("<li id=" + data['id'] + "><div>" +
data['player_name'] + "</div></li>");
}
$(".vertical-timeline").append(ul)
}
$("a.details").on("click", function(e) {
e.preventDefault();
$(".player_div").hide();
$(".player_timeline").show();
// MOVE TO PARTICULAR LI
});
CSS
.player_timeline {
height: 700 px;
margin - bottom: 100 px;
}
.vertical - timeline {
overflow - y: scroll;
height: 500 px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section class="player-div">
<table class="table table-responsive">
<tbody>
</tbody>
</table>
</section <section class="player_timeline" style="display:none;">
<div class="vertical-timeline">
</div>
</section>
沒有你的代碼,它可以是很難爲你提供一個正確的答案,因爲我們只能猜測你的代碼看起來像 –
對不起加入 –
@RinsenS你試過'碼$(文件)。在(「點擊「,」a.details「,函數(e){'? –