我的函数遵循参数中的值
function viewStudent(schoolName, fullName, class, rollnumber) {
}
以下是存储在学生对象中的值:
schoolName="St Joseph's School"
fullName="xyz"
rollNumber=2019,
在调用 viewStudent 时,我将值传递为:
onclick="changeFormStatus('${studentValue.schoolName}','${studentValue.fullName}',
'${studentValue.rollNumber}', '${studentValue.class}')"
但是由于 schoolName 包含撇号,因此给出错误 "missing )"
。任何想法我如何处理这个问题。
最佳答案
在参数上使用反引号(`)而不是撇号('):
onclick="changeFormStatus(`${studentValue.schoolName}`,`${studentValue.fullName}`,
`${studentValue.rollNumber}`, `${studentValue.class}`)"
关于javascript - 调用 javascript 函数时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54867033/