gpt4 book ai didi

javascript - 使用 Javascript 传递选定的复选框值

转载 作者:行者123 更新时间:2023-11-28 17:17:09 24 4
gpt4 key购买 nike

我有一个表,表中的最后一列有一个复选框,当用户单击复选框时,我想将行值传递给不同的函数,但是当我这样做时,代码不会似乎没有开火,我错过了什么吗?

 function GetContractors(companyName) {

var workforce = companyName;

$.ajax({

type: 'GET',
url: '@Url.Action("getContractors","Permit")',
contentType: "application/json; charset=utf-8",
dataType: "json",
data: { "workforce": workforce },
success: function (result) {

$("#mainData").empty();

$.each(JSON.parse(result),
function (i, item) {

var row = i + 1;

$("#mainData").append(

"<tr>" +

"<td id='process_" + row + "'" + ">" + item.ContractorName + "</td>" +

"<td bgcolor= " + "'" + cellColour1 + "'" + " id='process_" + row + "'" + ">" + parseJsonDate(item.InductionExpiry) + "</td>" +

"<td bgcolor= " + "'" + cellColour + "'" + " id='process_" + row + "'" + ">" + parseJsonDate(item.InsuranceExpiry) + "</td>" +

"<td id='Action" + row + "'" + ">" +

"<checkbox id='checkbox' class='btn btn-xs btn-success " +
"'" + "onclick='SelectedUser(" + item.ContractorName + ")" +
"'" + ">" + "<i class='glyphicon glyphicon-trash" +
"'" + "></i>" + "</checkbox>" + "&nbsp" +

"</tr>");

});
},
error: function (result) {

alert(result);
}
});
};

function SelectedUser(name)
{
alert(name);
}

最佳答案

试试这个:

"onclick='SelectedUser(\"" + item.ContractorName + "\")" +

您正在通过:

onclick='SelectedUser(Bob)'

它期望一个对象,但应该是

onclick='SelectedUser("Bob")'

\" 转义双引号

关于javascript - 使用 Javascript 传递选定的复选框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53207485/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com