0
我有頂部的more
鏈接的員工列表。jQuery - 查找最近的元素並替換文字
如果我點擊更多信息鏈接,我想獲得相關元素,並在底部顯示的值...
請看看下面的代碼並指導我?
$(document).ready(function(){
var empName = $(this).closest('.emp-details').find('.ename').text();
var empDesignation = $(this).closest('.emp-details').find('.edesignation').text();
$('.more-info').on('click', function(){
$('#info-container').show();
$('#info-container #empname').text(empName);
$('#info-container #designation').text(empDesignation);
});
});
設置你的變量** **裏面點擊處理... –
您正在運行'最接近()'對'document',這是最高級別,所以它會永遠找不到任何'.emp-details'。你的意思是把這兩行放在點擊處理程序中嗎? – Rhumborl