我正在我的 JS 函数中构建一个 html 字符串,并通过 AJAX 调用将其附加到我的 div 中,但我收到上述错误,我不明白为什么它会为一个部分而不是另一部分抛出错误。< /p>
html += "<td>" + employeeid + "</td><td onclick='getemployeesig(" + signature + ")'>Show Signature</td>...
上面的这个工作正常,但下面没有并抛出错误。名字是一个集合。
names.forEach(function (value) {
let bs = value.replace(/\s+/g, '');
let cs = bs.replace('"', '');
supervisorshtml += "<a href='#' onclick=supervisorFilter("+cs+")>" + value + "</a>";
})
我是这样附加的
$("#trainingTable").append(html);
$("#superVisorList").append(supervisorshtml);
我的功能是
function supervisorFilter(supervisorId) {
alert("Called");
}
function getemployeesig(employeeid) {
alert("Called");
}
请注意,我尝试绑定的 html 是
<div class="dropdown">
<button class="dropbtn">Select Supervisor</button>
<div class="dropdown-content" id="superVisorList">
</div>
</div>
而这一切都是在
$(document).ready(function () { }
答案 0 :(得分:0)
我发现了我的问题,我没有在“+cs+”前后添加单引号
supervisorshtml += "<a href='#' onclick=supervisorFilter("+cs+")>" + value + "</a>";
到
supervisorshtml += "<a href='#' onclick=supervisorFilter('"+cs+"')>" + value + "</a>";