我已经通过 js 生成了复选框:
anwsersCount = question.ChoiceQuestionAnwsers().length;
questionBodyContainer = document.getElementById('questionBody');
//self.ChoosedQuestionAnwsers = question.ChoiceQuestionAnwsers;
for (var i = 0; i < anwsersCount; i++) {
var newOption = document.createElement("input");
var newOptionLabel = document.createElement("label");
newOption.type = "checkbox";
newOption.id = i;
newOption.value = i;
newOptionLabel.for = i;
newOptionLabel.setAttribute("style", "margin-left: 5px");
newOption.onclick = function(event) {
alert('alert');
};
newOptionLabel.innerHTML = question.ChoiceQuestionAnwsers()[i].Text;
// questionBodyContainer.innerHTML += question.ChoiceQuestionAnwsers()[i].Text + "<p>";
// questionBodyContainer.appendChild(newOption);
questionBodyContainer.appendChild(newOption);
questionBodyContainer.appendChild(newOptionLabel);
questionBodyContainer.innerHTML += "<p>";
//self.ChoosedQuestionAnwsers.push(question.ChoiceQuestionAnwsers()[i]);
}
并且生成的复选框的 onclick 事件不起作用。你有什么想法如何让它发挥作用吗?