在表单内部单击时,表单会自动尝试重新提交,我无法弄清楚代码的哪一部分导致它出现这样的行为。在 createTable 函数中,在给定域之后创建一个表。但我无法选择输出中的任何控件。我在这里附上了 jsfiddle 代码链接:http: //jsfiddle.net/rasikaceg/S7kWM/
function createTable() {
document.getElementById("table_container").innerHTML = "";
var input_domain = document.forms["form1"]["DomainName"].value;
if (input_domain == null || input_domain == "") return;
var table = document.createElement("table"),
tablehead = document.createElement("thead"),
theadrow = document.createElement("tr"),
th1 = document.createElement("th"),
th2 = document.createElement("th"),
th3 = document.createElement("th"),
th4 = document.createElement("th");
th1.appendChild(document.createTextNode("Website"));
th2.appendChild(document.createTextNode("Enable/Disable Live Update for LM and CBD"));
th3.appendChild(document.createTextNode("From Date"));
th4.appendChild(document.createTextNode("To Date"));
theadrow.appendChild(th1);
theadrow.appendChild(th2);
theadrow.appendChild(th3);
theadrow.appendChild(th4);
tablehead.appendChild(theadrow);
table.appendChild(tablehead);
var names = ["website1", "website2"];
var container = document.getElementById("table_container");
var tablebody = document.createElement("tbody");
for (var i = 0, len = names.length; i < len; ++i) {
var row = document.createElement("tr"),
column1 = document.createElement("td"),
column2 = document.createElement("td"),
column3 = document.createElement("td"),
column4 = document.createElement("td"),
checkbox = document.createElement('input');
checkbox.type = "checkbox";
checkbox.name = names[i];
checkbox.value = names[i];
checkbox.id = names[i];
var label = document.createElement('label')
label.htmlFor = names[i];
label.appendChild(document.createTextNode(names[i]));
column1.appendChild(checkbox);
column1.appendChild(label);
var dropdown = document.createElement("select");
dropdown.name = names[i] + "_select";
var op1 = new Option();
op1.value = "enable";
op1.text = "enable";
var op2 = new Option();
op2.value = "disable";
op2.text = "disable";
dropdown.options.add(op1);
dropdown.options.add(op2);
column2.appendChild(dropdown);
var datetime_from = document.createElement('input');
datetime_from.type = "datetime-local";
datetime_from.name = names[i] + "_from";
column3.appendChild(datetime_from);
var datetime_to = document.createElement('input');
datetime_to.type = "datetime-local";
datetime_to.name = names[i] + "_to";
column4.appendChild(datetime_to);
row.appendChild(column1);
row.appendChild(column2);
row.appendChild(column3);
row.appendChild(column4);
tablebody.appendChild(row);
}
table.appendChild(tablebody);
document.getElementById("table_container").appendChild(table);
}