我正在尝试使用 ajax 处理多种表单。假设我有#formA 和#formB。在submitForm()函数中,我有以下内容:
function submitForm() {
var currentForm = $(this);
if (currentForm == "#formA") {
//do this
}
else if (currentForm == "#formB"){
//do that
}
}
但是这种方法行不通。处理这个问题的最佳方法是什么? 提前致谢。
最佳答案
尝试修改您的代码:
function submitForm() {
var currentForm = $(this);
if (currentForm.attr("id") == "formA") {
//do this
}
else if (currentForm.attr("id") == "formB") {
//do that
}
}
关于javascript - 使用ajax处理多种表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7143027/