当我在成功的 ajax 调用后尝试渲染表格单元格时遇到问题。
如何将 id
放入函数 deleteServiceIdFromInput()
中?
我尝试过:
deleteServiceIdFromInput('"+ id +"');
我也尝试添加\"\"
,但还是不行。
任何建议都会很好,谢谢。
$.ajax({
type: "POST",
url: "./OTTProductMapServIDAjaxSubmit.do",
dataType: 'json',
cache: false,
data: {"productID":productID,"serviceID":serviceID, "method":"searchSerivceById"},
success: function(data){
document.getElementById("listOfServiceID").value;
if (data != null){
var table = document.getElementById("serviceMappingTable");
var row = table.insertRow(1);
row.align="center";
row.onmouseover = function(){this.bgColor = '#C0C0C0';};
row.onmouseout = function(){this.bgColor = '#FFFFFF';};
var cell1 = row.insertCell(0);
cell1.innerHTML= '<a href="javascript:deleteServiceIdFromInput('"+ id +"')" class="cssBtn">Delete</a>';
insertServiceIdToInput(data.serv_id);
}
我正在寻找的最终结果,它将以 HTML 形式呈现,如下所示:
href="javascript:deleteServiceIdFromInput(' id ')"
对于我尝试过的解决方案,在 HTML 中重新显示为:
href="javascript:deleteServiceIdFromInput( id )" <-- quote is missing
最佳答案
您可以使用
cell1.innerHTML= '<a href="javascript:deleteServiceIdFromInput("'+ id +'") class="cssBtn">Delete</a>'
关于javascript - 如何在引用 javascript 中添加引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32498776/