提交表单时,它会通过JavaScript获取句柄。在JavaScript中,我正在为 serializeArray 循环显示名为“ action ”的隐藏字段。
/* This is the funtion that handles the action from .ajax-about form */
function ajax_about_birthday(dataArray){
alert("Works!");
}
$("#about-form-horizontal .ajax-about").submit(function(){
var form, dataArray, action;
form = $(this).serializeArray();
dataArray = form, dataObj = {};
$(dataArray).each(function(i, field){
dataObj[field.name] = field.value;
});
action = dataObj['action'];
action(); // I' am stuck here, how will I call the function using the value from action variable
});
从上面的代码中,我在控制台上没有收到任何错误。