JavaScript 我无法将字符串参数发送到函数,即使我可以在点击事件上发送带有 div.innerHTML 的 int 参数

JavaScript I can't send string parameter to function even I can send int parameter with div.innerHTML on click event

script type="text/javascript"> 
function QueryAgain(teammate){
document.getElementById("researcher-name").value=teammate;
document.getElementById("publication-name").value="";
document.getElementById("publication-year").value="";

}
function createDiv() { 
const boxes = document.querySelectorAll('.cards');
boxes.forEach(box => {
  box.remove();
});

for(var i=0;i<size;i++){
let div = document.createElement('div');
div.innerText = document.getElementById('getText').innerText;
div.id="card"+i;
div.innerHTML="<br />"+"<br />"+"<br />"+"<br />"+"RESEARCHER ID:"+researcher_id[i]+"<br />"+"RESEARCHER NAME:"+researcher_name[i]+"<br />"+"RESEARCHER SURNAME:"+researcher_surname[i]+"<br />"+"RESEARCHER PUBLICATON NAME:"+publication_name_general[i]+"<br />"+"RESEARCHER PUBLICATON YEAR:"+publication_year_general[i]+"<br />"+"RESEARCHER PUBLICATON PLACE:"+publication_place_general[i]+"<br />"+"RESEARCHER PUBLICATON TYPE:"+publication_type_general[i]+"<br />"+"RESEARCHER TEAMMATES NAME:"+"<br />"+"<br />"+"<br />"+"<br />"+"<br />"

for(var j=0;j<researcher_teammate[i].length;j++){
  holder=teammate_id_general[i][j];
  holder2=researcher_teammate[i][j];
  console.log(holder2);
  console.log(typeof(holder2));
  div.innerHTML+="<br />"+"<a href='#nav'id='teammate'"+'onclick=QueryAgain(\''+holder+'\')'+">"+researcher_teammate[i][j]+"</a>"+"<br />";
}
div.className="cards";                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
div.style.height="300px";
div.style.border="4px solid black";
div.style.background="#E2EFF3";
div.style.display= "flex";
div.style.alignItems="center";
div.style.justifyContent="center";
div.style.marginLeft="400px";
div.style.marginRight="400px";
div.style.marginTop="50px";
document.body.appendChild(div);
console.log(researcher_teammate_name);


}
const countAll = document.querySelectorAll('.cards').length;
console.log("COUNT ALL:",countAll);
function getIdFormA(obj) {
  window.alert(window.location.href += "?id=" + obj);
}


}
</script>

这是我的代码的一部分,我正在尝试将字符串参数发送到下面的这个 QueryAgain() 函数:

function QueryAgain(teammate){
document.getElementById("researcher-name").value=teammate;
document.getElementById("publication-name").value="";
document.getElementById("publication-year").value="";
}

我正在使用以下代码发送参数:

for(var j=0;j<researcher_teammate[i].length;j++){
  holder=teammate_id_general[i][j];
  holder2=researcher_teammate[i][j];
  div.innerHTML+="<br />"+"<a href='#nav'id='teammate'"+'onclick=QueryAgain(\''+holder2+'\')'+">"+researcher_teammate[i][j]+"</a>"+"<br />";
}

holder 变量是一个整数值,我可以将它发送到 QueryAgain() 函数并写入 value.When我正在尝试发送 holder2(它是字符串变量),它在下面给出了这个错误

Uncaught SyntaxError: Invalid or unexpected token (at (index):1:12)

我只想将这两个变量发送到函数,但我什至无法发送字符串 parameter.So 我想我需要学习如何发送 it.I 我想我正在做一个语法错误但我不明白原因,也无法解决。 以下是一些我试过但没有用的代码:

我试过一次:

div.innerHTML+="<br />"+"<a href='#nav'id='teammate'"+'onclick=QueryAgain('+holder2+')'+">"+researcher_teammate[i][j]+"</a>"+"<br />";

并在这里查找问题并找到了一些代码-->This code has taken by this questeion

div.innerHTML+="<br />"+"<a href='#nav'id='teammate'"+'onclick=QueryAgain(\''+holder2+'\')'+">"+researcher_teammate[i] 
[j]+"</a>"+"<br />";

而这段代码没有解决 error.What 是错误的原因,我该如何解决? 我正在尝试同时将整数(holder)和字符串(holder2)值发送到函数。

只需使用字符串模板文字

div.innerHTML += `
  <br />
  <a 
    href='#nav'
    id='teammate'
    onclick="QueryAgain('${holder}')">
    ${researcher_teammate[i][j]}
  </a>
  <br />
`;