내용

글번호 689
작성자 heojk
작성일 2017-06-14 17:08:41
제목 [Re]HTML 문서 파싱하기 시작파일
내용
var nameList = document.querySelectorAll("table tr > td:nth-child(2)");
var salList = document.querySelectorAll("table tr > td:nth-child(6)");
var commList = document.querySelectorAll("table tr > td:nth-child(7)");
var name, sal, comm;
var annualSal;
var totalSal = 0;

var deptTH = document.querySelector("table tr > th:nth-last-child(2)");
var annSalTH = document.createElement("th");
annSalTH.textContent = "연봉";
deptTH.parentNode.insertBefore(annSalTH, deptTH)

console.log(annSalTH);
for(var i=0; i<nameList.length; i++) {
	name = nameList[i].textContent;
	sal = parseFloat(salList[i].textContent);
	comm = parseFloat(commList[i].textContent);
	annualSal = sal*12 + comm;
	console.log("%s님의 연봉은 %f입니다...", name, annualSal);
	totalSal += annualSal;

	var annSalNode = document.createElement("td")
	annSalNode.textContent = annualSal;
	commList[i].parentNode.insertBefore(annSalNode, commList[i].nextSibling);
}

document.querySelector("#total_sal").textContent = totalSal;