我编写了一个jquery函数,它动态创建一个id为("#btn_sendStudentAnswer")
的按钮:
$("#btn_getAnswers").one("click",function(){
$.ajax({type :"POST",
url: "DBCOMANSWERS.php",
dataType:"json",
data:{input:$("#input").val()},
success: function(result){ //Performs an async AJAX request
if(result){
result.forEach(function(i,v){
$("#output").append("<br><input type='checkbox' id='" + i[1]+ "'>" + i[0] + "</input>"); //create checkboxes representative for the 3 answers
})
$("#output").append("<br><button id='btn_sendStudentAnswer'>" + "Prüfen" + "</button>"); //create button to check if students answer is correct.
}
}
});
});
到目前为止,工作正常。我想要的是,在单击创建的按钮(#btn_sendStudentAnswer)
时执行某些操作。我编写了点击事件,如下所示:
$("#btn_sendStudentAnswer").click(function(){
debugger;
$.ajax({type:"POST",
url: "DBCOMCHECKANSWERS.php",
dataType:"json",
success: function(result){
//if answer were right/wrong mark them
}
});
});
但它永远不会到达debugger;
。
&#34; Web-Developer-Tool&#34; Chrome没有显示任何错误或异常情况。
是否存在编程错误或者是否需要单击动态创建的按钮作出反应?