JS取当前元素的“邻居”

function showRecentMsgClick(senderId, senderName, msgId, userId) {	
	var o = event.srcElement;
	while ("IMG" != o.tagName){
		o = o.parentElement;
    }
	var img = o;
    while ("TR" != o.tagName){
		o = o.parentElement;
    }
	o = o.nextSibling;
	if ('none' == o.style.display){
		img.src = document.all.actForm.unfoldImg.value;
		showHistoryMsg(senderId, senderName, msgId, userId, o);
		o.style.display = 'block';
    } else {
		img.src = document.all.actForm.initImg.value;
		o.style.display = 'none';
	}
}

obj.previousSibling是取前一个元素
obj.nextSibling是取后一个元素

你可能感兴趣的:(js)