모든 것을 시도했지만 코드가 작동하지 않습니다. 나는 이유를 모른다. 여기JavaScript : string.replace()가 작동하지 않습니다. 무엇이 문제입니까?
은 다음과 같습니다
var table = $("#cpTableBody").html();
$("#cpTableBody").html('');
var tmpContent = "";
for (i=0; i<cpData.length; i++) {
var tmpTable = table;
tmpTable.replace(/{firstname}/g, cpData[i].contact_person.firstname);
tmpTable.replace(/{lastname}/g, cpData[i].contact_person.lastname);
tmpContent += tmpTable;
}
$("#cpTableBody").html(tmpContent);
'; '는 무의미한 재 할당으로 보이고, 첫 번째 루프 반복에서'{firstname} '과'{lastname} '이 대체되고 다른 모든 반복은 아무것도 수행하지 않는다는 것을 의미합니다. 내가 놓친 게 있니? –