传递参数时,JavaScript 不会调用函数。
我正在动态创建 HTML。
checkbox2 = document.createElement("<input type=\"checkbox\" name=\"wdrs_contact\" checked=\"Yes\" onclick =\"setPartnersInfo('\"+id+\"');\" />");
function setPartnersInfo(ch)
{
alert(ch)
}
但是当我在函数调用中没有参数时,它正在工作。
详情如下:
function createPartnerTable() {
var partnerInfo = document.getElementById("partnersInfo");
var data = partnerInfo.value;
// everything was successful so now come back and update, first clear the old attributes table
var partnersBody = document.getElementById("partnersBody");
var rowCount = partnersBody.rows.length;
for( var i = 0; i < rowCount; i++ )
{
partnersBody.deleteRow(0);
}
if (data ==null || data.length==0)
return;
// now parse and insert each partner row
//alert("data : "+data);
var index = 0;
var lastIndex = 0;
while( index < data.length && index != -1 )
{
lastIndex = data.indexOf("|", index);
if( lastIndex == -1 ){
break;
}
var id = data.substring(index, lastIndex);
index = lastIndex + 1;
lastIndex = data.indexOf("|", index);
var name = data.substring(index, lastIndex);
index = lastIndex + 1;
lastIndex = data.indexOf("|", index);
var partnerType = data.substring(index, lastIndex);
index = lastIndex + 1;
lastIndex = data.indexOf("|", index);
var status = data.substring(index, lastIndex);
index = lastIndex + 1;
lastIndex = data.indexOf(";", index);
var jdeCode = data.substring(index, lastIndex);
//ganessin
index = lastIndex + 1;
lastIndex = data.indexOf("#", index);
var wdrsContact = data.substring(index, lastIndex);
row = partnersBody.insertRow(partnersBody.rows.length);
//check box with id for removal
var checkboxCell = row.insertCell(0);
checkboxCell.align="center";
var checkbox = document.createElement('<input type="checkbox" name="selectedPartnerIds" />');
//var checkbox = document.createElement("input");
//checkbox.type = 'checkbox';
//checkbox.checked=false;
//checkbox.name = 'selectedPartnerIds';
checkbox.value=id;
//checkbox.style.align = "center";
//checkbox.style.width = '40%';
checkboxCell.appendChild(checkbox);
var check = document.getElementsByName('selectedPartnerIds');
//Name
var nameCell = row.insertCell(1);
nameCell.appendChild(document.createTextNode(name));
//Partner Type
var partnerTypeCell = row.insertCell(2);
partnerTypeCell.align="center";
partnerTypeCell.appendChild(document.createTextNode(partnerType));
//Status
var statusCell = row.insertCell(3);
statusCell.align="center";
statusCell.appendChild(document.createTextNode(status));
//JDE Code
var jdeCodeCell = row.insertCell(4);
jdeCodeCell.align="center";
jdeCodeCell.appendChild(document.createTextNode(jdeCode));
//ganessin
var checkboxCell2 = row.insertCell(5);
checkboxCell2.align="center";
var checkbox2 = "";
//alert("wdrsContact "+wdrsContact);
var x = "setPartnersInfo("+id+")";
alert("x = "+x);
if(wdrsContact == "true")
{
alert("true");
//checkbox2 = document.createElement('<input type="checkbox" name="wdrs_contact" checked="Yes" onclick="+x+" onchange="+x+" />');
checkbox2 = document.createElement("<input type=\"checkbox\" name=\"wdrs_contact\" checked=\"Yes\" onclick =\"setPartnersInfo(\"+id+\");\" />");
//String(document.createElement('<input type="checkbox" name="wdrs_contact" checked="Yes" onchange="setPartnersInfo("+id+");"/>'))
}
else
{
alert("false");
//checkbox2 = document.createElement('<input type="checkbox" name="wdrs_contact" onclick="+x+" onchange="+x+" />');
checkbox2 = document.createElement("<input type=\"checkbox\" name=\"wdrs_contact\" onclick=\"setPartnersInfo(\"+id+\");\" />");
}
//alert("id "+id);
//checkbox2.value=id;
// alert("checkbox2 "+checkbox2);
checkboxCell2.appendChild(checkbox2);
// increment the index to process next
index = lastIndex + 1;
}
}